Mixed Use of encode script and normal script and Solution

Source: Internet
Author: User

When I first performed script encoding six months ago, I had no experience in using it. So I asked 51js if there was any problem with mixing the encode script and the normal script? The results did not receive any constructive comments, which at least explained two problems: No one cares, and no problem. Of course, I prefer to accept the latter result and start the mixed use of the encode script and the normal script.

With this understanding, I have made a lot of scripts, and it seems that I have never encountered any problems, so I am more confident in my original judgment. Once again, the results are implicitly calculated by IE. The mixed use of the encode script and the normal script is neither a problem nor a problem, but a problem may occur under specific conditions. See the following example:

Copy codeThe Code is as follows: <Head>
<Title> JScript Encode Research </title>
<Meta name = "author" content = "birdshome @ cnblogs"/>
</Head>
<Body>
<Script language = "jscript. encode" type = "text/jscript. encode">
#@~ ^ 8 gAAAA == ~, P ~, P, Pr (L ^ Ycw. WDWOza + Rtn/klo ~ XP6E mOkGUv #@#@&,~ P, P ~~, @#@&~, P ~ P ,~, P ~, P, lVDDcB} 4% + 1Y 2 MWYKOXa + Rtnd/moBbi &, P ~ P ,~ P, 8I @ # @ & PP ~~, P ~ P @ # @ &, P ~, P, PP} 4nnmcm \ + k/CLP ', WE mYbGU' * # @ & P ~ P ~~, P ~ ##@ & P, P ~~, PP ~~, P ~ L ^ nMYcEr (L + 1Yc \ + k/CoBbI #& P ,~ P, PP, fig = ^ #~ @
</Script>
<Script language = "jscript. encode" type = "text/jscript. encode">
#@~ ^ FgEAAA = ~, P ~, P, P0! X1OkKx ~ 2 mG ['#, '8 @#@&@#@&~~ P, P, P ~ 2U ^ KNnRa. WDWOza + R \ nk/Co ~ {PW! X1YkKxvb @ & P ~ P, P ~~, @#@&~ P, PP ,~~ P, P,. kOndkU + vv2 mG [Rw. GDWOXancHnk/mo + E # p #&, P ~ P, P ~~) I @ # @ &, PP ,~~ P, 2 mGNn t + d/mL + ,'~ W! XmOrKxc ###@ &, P ~, P, PPP @#@&~ P, P ~ P, P ~~, PMrYSk ncBAx1W [+ \/dlTnB * I #&, PP ~~, P ~ 8p ~, V0MAAA == #~ @
</Script>
<Script language = "jscript" type = "text/jscript">
Function Normal (){}
Normal. prototype. Message = function ()
{
WriteLine ('normal. prototype. message ');
};
Normal. Message = function ()
{
WriteLine ('normal. message ');
};
</Script>
<Script language = "jscript" type = "text/jscript">
Var msg = '. prototype. Message "Fail. <br> ';
Function WriteLine (msg) {document. write (msg + '<br> ');}

Var o = new Object ();
Try {o. Message ();}
Catch (e) {WriteLine ('call "object' + msg + e. message );}
Try {Object. Message ();}
Catch (e) {WriteLine ('call "Object. Message" Fail. <br> '+ e. message );}

Var e = new Encode ();
Try {e. Message ();}
Catch (e) {WriteLine ('call "encode' + msg + e. message );}
Encode. Message ();

Var n = new Normal ();
Try {n. Message ();}
Catch (e) {WriteLine ('call "Normal '+ msg + e. message );}
Normal. Message ();
</Script>
</Body>
</Html>

Save the above Code as a *. htm file. The result is as follows:

Call "Object. prototype. Message" Fail.
Object doesn' t support this property or method
Call "Object. Message" Fail.
Object doesn' t support this property or method
Encode. prototype. Message
Encode. Message
Normal. prototype. Message
Normal. Message
The above two jscript. encode codes are simple: Object. prototype. Message = function ()
{
Alert ('object. prototype. message ');
};
Object. Message = function ()
{
Alert ('object. message ');
};
Function Encode (){}
Encode. prototype. Message = function ()
{
WriteLine ('encode. prototype. message ');
};
Encode. Message = function ()
{
WriteLine ('encode. message ');
};
If we replace the above two sections of code with the two jscript. encode sections in the html, the subsequent operation will not cause any exception and the output will be: Object. prototype. Message
Object. Message
...
The above code examples have explained in detail the problem of the encode script code. That is, the prototype method and static method imported to the built-in JScript object cannot be referenced in non-encoding scripts. The Object in the above example is a built-in Object of JScript. We have imported a prototpye method and a static method Message () respectively (). For non-built-in object Encode, the prototype and static methods imported in the encoded code can be normally accessed in the non-encoded code.

So how to access the import method of built-in objects? In fact, the solution is not complex, but complicated. We need to use some wrapper methods to put them together with the encoded code so that we can access them in the non-encoding code. For example, we can wrap the above Object as follows:

Object. prototype. Message = function ()
{
WriteLine ('object. prototype. message ');
};
Object. Message = function ()
{
WriteLine ('object. message ');
};
Var obj = new Object ();

Function ObjectPrototypeMessage ()
{
Obj. Message ();
}
Function ObjectMessage ()
{
Object. Message ();
}
In this case, we can use wrapper methods such as ObjectPrototypeMessage and ObjectMessage to access the built-in object import method in the encoded code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.