把JS函数转URL形式

分享一个小技巧,个中乐趣请跨站师们自己体会:

<script type="text/javascript">
<!--
function func2URL(proc) {
    
return "javascript:(" + encodeURIComponent(proc.toString()) + ")();";
}

function test() {
    
var a = "hahaha\x41\x42";
    
var b = function(s) {
        alert(s);
    };
    
    b(a);
}

document.write(func2URL(test));
location.href 
= func2URL(test);
//-->
</script>
原文地址:https://www.cnblogs.com/luoluo/p/1399273.html