Home‎ > ‎WebDev‎ > ‎JavaScript‎ > ‎

HTMLescape

080620_11_30

クエリパラメタの取り込みをエスケープする

file:///Users/ytesaki/Desktop/htmlescape.html?&lt;h1&gt;h1 no moji&lt;/h1&gt;<br>
とかね。<br>
<br>
<br>
<script type="text/javascript">
String.prototype.htmlescape = function (){
 return this.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;") ;
}
document.write(unescape(location.href));
document.write('<br>');
document.write('<br>');
document.write(location.href);
document.write('<br>');
document.write('<br>');
document.write(unescape(location.href).htmlescape());

</script>

クエリパラメタの取り込みをエスケープする

file:///Users/ytesaki/Desktop/htmlescape.html?<h1>h1 no moji</h1>
とかね。


Comments