encode脚本和normal脚本混用的问题与解决方法_Javascript教程-查字典教程网
encode脚本和normal脚本混用的问题与解决方法
encode脚本和normal脚本混用的问题与解决方法
发布时间:2016-12-30 来源:查字典编辑
摘要:半年前第一次做脚本编码的时候,由于没有什么使用经验,于是在51js上询问了一下encode脚本和normal脚本混用是否有什么问题呢?结果没...

半年前第一次做脚本编码的时候,由于没有什么使用经验,于是在51js上询问了一下encode脚本和normal脚本混用是否有什么问题呢?结果没有得到任何有建设性的意见,这也至少说明了两个问题,一是没有人在意,二是就没有什么问题嘛。当然我更乐意于接受后一种结果,就开始了encode脚本和normal脚本的混合使用。

在这样的理解下做了很多的脚本,似乎也真的没有出现过什么问题,于是更加笃信自己当初的判断。结果又一次被IE暗算了,encode后的脚本和normal的脚本混和使用不是没有问题,也不是都有问题,只是在特定的条件下会出问题,真是晕死。看下面这个示例:

复制代码 代码如下:

<html>

<head>

<title>JScriptEncodeResearch</title>

<metaname="author"content="birdshome@cnblogs"/>

</head>

<body>

<scriptlanguage="jscript.encode"type="text/jscript.encode">

#@~^8gAAAA==~,P~,P,Pr(L^Ycw.WDWOza+Rtn/klo~xP6EmOkGUv#@#@&,~P,P~~,@#@&~,P~P,~,P~,P,lVDDcB}4%+1Y2MWYKOXa+Rtnd/moBbi@#@&,P~P,~P,8I@#@&PP~~,P~P@#@&,P~,P,PP}4NnmDR+k/CLP',WEmYbGU`*@#@&P~P~~,P~@#@&P,P~~,PP~~,P~l^nMYcEr(L+1Yc+k/CoBbI@#@&P,~P,PP,NIGjkAAA==^#~@

</script>

<scriptlanguage="jscript.encode"type="text/jscript.encode">

#@~^FgEAAA==~,P~,P,P0!x1OkKx~2mG[`#,`8@#@&@#@&~~P,P,P~2U^KNnRa.WDWOza+Rnk/Co~{PW!x1YkKxvb@#@&P~P,P~~,@#@&~P,PP,~~P,P,.kOndkU+vv2mG[Rw.GDWOXancHnk/mo+E#p@#@&,P~P,P~~)i@#@&@#@&,PP,~~P,2mGNnt+d/mL+,'~W!xmOrKxc#@#@&,P~,P,PPP@#@&~P,P~P,P~~,PMrYSkncBAx1W[+/dlTnB*i@#@&,PP~~,P~8p~,V0MAAA==^#~@

</script>

<scriptlanguage="jscript"type="text/jscript">

functionNormal(){}

Normal.prototype.Message=function()

{

WriteLine('Normal.prototype.Message');

};

Normal.Message=function()

{

WriteLine('Normal.Message');

};

</script>

<scriptlanguage="jscript"type="text/jscript">

varmsg='.prototype.Message"Fail.<br>';

functionWriteLine(msg){document.write(msg+'<br><br>');}

varo=newObject();

try{o.Message();}

catch(e){WriteLine('Call"Object'+msg+e.message);}

try{Object.Message();}

catch(e){WriteLine('Call"Object.Message"Fail.<br>'+e.message);}

vare=newEncode();

try{e.Message();}

catch(e){WriteLine('Call"Encode'+msg+e.message);}

Encode.Message();

varn=newNormal();

try{n.Message();}

catch(e){WriteLine('Call"Normal'+msg+e.message);}

Normal.Message();

</script>

</body>

</html>

把上面的代码存为一个*.htm文件,打开后得到结果为:

Call"Object.prototype.Message"Fail.

Objectdoesn'tsupportthispropertyormethod

Call"Object.Message"Fail.

Objectdoesn'tsupportthispropertyormethod

Encode.prototype.Message

Encode.Message

Normal.prototype.Message

Normal.Message

上面那两段jscript.encode的代码很简单,就是:Object.prototype.Message=function()

{

alert('Object.prototype.Message');

};

Object.Message=function()

{

alert('Object.Message');

};

functionEncode(){}

Encode.prototype.Message=function()

{

WriteLine('Encode.prototype.Message');

};

Encode.Message=function()

{

WriteLine('Encode.Message');

};

如果我们把上面两段代码替换那个html中的两段jscript.encode的代码,后面的运行将不会出任何异常,会得到这样的输出:Object.prototype.Message

Object.Message

...

上面这些代码实例的试验,已经详细的说明了encode脚本代码的问题。就是,不能在非编码脚本中,引用编码脚本中导入到JScript内置对象上的原型(prototype)方法和静态方法。上面示例中的Object就是JScript的一个内置对象,我们分别导入了一个prototpye方法和静态方法Message()。而对于非内置对象Encode,我们在已编码代码中导入的prototype和static方法,都可以在非编码代码中正常的访问。

那么怎么访问内置对象的导入方法呢?其实解决起来也不复杂,只是比较繁琐。我们需要使用一些wrapper方法,把他们和被编码的代码放在一起,就可以在非编码代码中访问了,比如上面的Object的导入,我们可以这样包装它:

Object.prototype.Message=function()

{

WriteLine('Object.prototype.Message');

};

Object.Message=function()

{

WriteLine('Object.Message');

};

varobj=newObject();

functionObjectPrototypeMessage()

{

obj.Message();

}

functionObjectMessage()

{

Object.Message();

}

这时,我们就可以通过ObjectPrototypeMessage和ObjectMessage这样的wrapper方法访问到已编码代码中内置对象的导入方法了。

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类