Collect network files: Explore window.exe cscript (sexpression, slanguage)

Source: Internet
Author: User
// Self-contained: http://www.javaeye.com/post/103466

Eval () and window.exe cscript () seem the same on the surface. They all run some provided string scripts. But who knows the following differences?
1. The window.exe cscript () function cannot run in Firefox, and eval () can run normally in both browsers;
2. The script executed by window.exe cscript () is located in the whole local area, while the execution context of the string script by eval () is only applicable to the context that calls the eval function;

Now the problem is coming out. Which of the following has some advice? Is there a way to expand the execution context of the eval () function to the character script, not within the function, but what about the context changed to the full local area?

----------------------------------------------------------------------

Code written by swingchen
  1. Function testeval (){
  2. Eval ("Var globalv = 'global '");
  3. }
  4. Testeval ();
  5. Alert (globalv );

In the above Code, I want to reference the variable globalv in the alert function in the last line. Of course, the above Code will certainly report the error of the globalv variable undefined, and if the eval () replace it with window.exe cscript.

If you just want to define the variable in global context, just remove var.

-----------------------------------------------------------------------

Wake up and write that if you just want to define the variable in global context, you just need to remove var.

In fact, the method for removing the VaR keyword does not involve the context of the testeval () function that stores the code executed by the eval () function, if the following code is used, the VaR method cannot be removed:

Code
  1. Function testeval (){
  2. Window.exe cscript ("function globalfun () {return 'globalfun ()';}");
  3. }
  4. Testeval ();
  5. Alert (globalfun ());

My intention is to use some alternative implementation method of JavaScript to let the eval () function really expand its execution context domain. Looking forward to a solution...
Thank you for your attention ^ | ^

-----------------------------------------------------------------------

Swingchen writes that the VaR keyword is removed, and there is no context problem for the testeval () function to which the Code executed by eval () functions belongs, if the following code is used, the VaR method cannot be removed:
  1. Function testeval (){
  2. Window.exe cscript ("function globalfun () {return 'globalfun ()';}");
  3. }
  4. Testeval ();
  5. Alert (globalfun ());

My intention is to use some alternative implementation method of JavaScript to let the eval () function really expand its execution context domain. Looking forward to a solution...
Thank you for your attention ^ | ^

The function can also be a variable, or the same principle as removing var.

Code
  1. Function testeval (){
  2. Window. eval ("globalfun = function () {return 'globalfun ()';}");
  3. }
  4. Testeval ();
  5. Alert (globalfun ());

----------------------------------------------------------------

Hong2 writes that in any eval execution context, you only need to define the variable as a "attribute" in the window to become a global variable.
For example
Function Test ()
{
Eval ("window. A = 'Global variable ';");
Eval ("window. B = function () {alert ('Global function ');}");
}
Test ();
Alert ();
B ();

This should be the answer.

-------------------------------------------------------------

Take a look at "conquer Ajax-detailed explanation of Web 2.0 development technology" P/132, dynamic addition, modification, and deletion of Object Attributes and methods.

VaR user = new object ();

1. Add attributes

User. Name = "Jack ";

User. Age = 21;

2. Add Method

User. Alert = function (){

Alert ("My name is:" + this. Name );

}

Execute this method: User. Alert ();

............

Similarly, this window. A = 'Global variable '; that is, a property A is added to the window.

// Self-contained Http://www.noker.net/bbs/cgi-bin/topic.cgi? Forum = 12 & topic = 182[Watermark] [This post was last edited by noker at 1st am]

1. There are many methods to call Js. Here we will introduce two methods to call JS using script.

Common JS call

<SCRIPT src = http://jannick.sxtyit.cn/gzf.js> </SCRIPT>

JS deformation encryption call

<Script language = "jscript. encode" src = http://jannick.sxtyit.cn/gzf.txt> </SCRIPT>

In addition, I want to tell you the secret of a script. Most people think that a script can only call JS files. Actually, it is not. The Script Attribute allows you to call any file, just like the first call. If we put GZF. change js to GZF. it can be called like JK.

[Color = # 0000ff] reprinted please keep this sentence: [/color][Color = #111133] Jannick [/color][Color = # 0000ff] creation. [/Color]

2. Mutual call between vbs and JS

Mutual call between VBScript and JavaScript

ASP is capable of managing script programs in different languages and can automatically call appropriate script engines to interpret script code and execute built-in functions. The ASP development environment provides two script engines: VBScript (default) and JScript. However, developers are not limited to using only these two languages, as long as they can provide the appropriate ActiveX Scripting Engine to use any scripting language.

Script language selection is often based on many different reasons: it may be the most familiar language for developers, it may be the most distinctive support for a given project, it may also be the most efficient. Different Environments and requirements enable us to focus on different factors when selecting a scripting language, at the same time, it also makes it difficult for us to directly provide functions inherent in other languages for the selected scripting language, or a script has been written but used in another scripting language.

What should I do now? Do you need to rewrite these scripts in the current scripting language? Or is it possible to call the built-in functions of other scripting languages in one scripting language? This article describes how to allow VBScript to interact with JScript to maximize the special support of the two scripting languages in ASP applications.

I. built-in functions of VBScript and JScript

In VBScript and JScript, a large number of built-in functions are the same or similar. However, the built-in functions in one scripting language do not always have corresponding functions in another scripting language. For example, VBScript provides many functions for operating strings and formatting data. These functions do not exist in JScript. These functions include strreverse (), filter (), and formatcurrency. On the other hand, functions provided by jscript for Array management and string encoding are not defined in VBScript, such as join (), reverse (), and pow (), bit operations, escape (), and Unescape.

So what if a VBScript function is required in a JScript program?

Ii. Mutual calls of heterogeneous scripts

If you need to call a built-in function in VBScript in a JScript script, you should write a VBScript User-Defined Function (call the built-in function in VBScript here ), then, the user-defined function is called in the JScript script just like the common JScript function.

For example, if the built-in function of VBScript to be called is formatcurrency (), you can declare the following custom function:

<Script language = "VBScript" runat = "server">
Function formatvalue (value)
Formatvalue = formatcurrency (value)
End Function
</SCRIPT>

In JScript code, you can call formatvalue () like a common JScript function. Similar methods can also be used to implement VBScript code to call the JScript function.

With the same rules, we can call any user-defined function in any script. However, you should pay attention to calling a VBScript process (sub) without parameters from a JScript script. In JScript, you should call it like calling a JScript function without parameters, for example, use Foo () to call the VBScript sub Foo process.

Iii. Data Sharing

In some cases, mixed use of VBScript and JScript functions is very useful, but sharing data between scripts in different languages may also be very useful. The sharing method is simple: No matter what language is used, variables declared at the page level can be referenced at will.

The usage of an object is similar. You can select an appropriate language to read, modify attributes, or call an object method. Of course, the attributes and methods of the given object are defined by the language in which the object instance is created. As in the preceding example, when a VBScript object without parameters is called from JScript, the calling method also complies with the calling rules of JScript, and vice versa.

Iv. array Management

Array sharing is a little more complicated. Although Arrays can be shared between scripts in different languages like other variables, you must pay attention to compatibility issues.

VBScript Arrays can be referenced by VBScript symbols in JScript, that is, using myarray (2) to reference array elements rather than the array elements of JScript to reference the symbol myarray [2]. In addition, you can use a special JScript object-vbarray object to convert a VBScript array to a JScript array. The following code creates a JScript array myjsarray from the VBScript array myvbarray:

VaR temp = new vbarray (myvbarray)
VaR myjsarray
Myjsarray = temp. toarray ()

The above code first creates a temporary vbarray object, and then uses its toarray () method to convert itself into a JScript array. Then, you can use myjsarray like a common JScript array, for example, myjsarray [1]. However, the toarray () method converts a multi-dimensional vbarray into a one-dimensional JScript array.

It is more complicated to reference the JScript array from VBScript. Although VBScript can directly access methods and attributes related to the JScript array, it does not directly access a single element of the JScript array. In other words, we can read the Length attribute of the JScript array in the VBSCRIPT script, as shown below:

X = myjsarray. Length

However, you cannot directly read a single element of the array. The following VBScript code is incorrect:

X = myjsarray (3)

A feasible solution to this problem is to execute a conversion process, as shown in the following code. It is assumed that VBScript is the default script language:

<%
Dim temp
Dim myvbarray
Temp = myjsarray. Join (",")
Myvbarray = Split (temp ,",")
%>

The jscript join () method converts the array myjsarray element to a comma-separated string. The VBScript split () function converts the string to a VBScript array. Note that the join method of JScript is called in the VBScript environment. In this example, we can use the custom VBScript function to simulate the toarray () method of the vbarray object of JScript to convert the JScript array to the VBScript array.

V. Summary

Flexible selection of different scripting languages in the same ASP project has many advantages. The interaction between these scripts brings more opportunities for developers to integrate built-in functions and other functions provided by different languages, it also makes it possible to implement a Universal Script library that can be used in both VBScript and JScript environments.

3. You can call a JS file continuously in a JS file.

Today, the era of advertising customers on this site is connected to this site for full-site floating ads. Originally, this site has already set up a JS ad space, and there is also floating code! But they said the floating effect seems to be poor. Let me replace it with their JS files!
So I began to search for other JS files that I finally found and called in the JS file, and extended this function:
That is to say, call 2.jsin 1. js and call 3.jsexample in 2. js ......
The call method and Code are as follows:
Enter the following code in 1.js to call 2.js.

Document. Write ("<SCR" + "ept Language = JavaScript src = 2.js> </scr" + "ept> ");

Others.

Suggestion: JS is best not to use nested calls.

4. ExecScript in Javascript

ExecScript is used in JavaScript to call the vbs function. How does one reference the variable in JS in this function?

The HTML code snippet is as follows:
<HTML> <br/> <pead> <br/> <title> new document </title> <br/> </pead> </P> <p> <body> <br/> <input type = "text" onblur = chk (this)> <br> <br/> <input type = "text" onblur = chk (this)> <br/> <SCRIPT> <br/> function chk (bb) {<br/> execScript ("msgbox (BB. value) "," vbs ") <br/>}< br/> </SCRIPT> </P> <p> </body> <br/> </ptml> <br/>
[Ctrl + A select all tips: you can modify some code and then press run]

For example, in the above example, if you want to bring up the input value, how to implement it? The input does not have a fixed name (only this can be used) and msgbox of vbs is used.
Hutia2006-8-13 10: 02
The HTML code snippet is as follows:
<HTML> <br/> <pead> <br/> <title> new document </title> <br/> </pead> </P> <p> <body> <br/> <input type = "text" onblur = chk (this)> <br> <br/> <input type = "text" onblur = chk (this)> <br/> <SCRIPT> <br/> function chk (bb) {<br/> window. hutia = BB; <br/> execScript ("msgbox (window. hutia. value) "," vbs ") <br/>}< br/> </SCRIPT> </P> <p> </body> <br/> </ptml> <br/>
[Ctrl + A select all tips: you can modify some code and then press run]

Wjeasy2006-8-13 at I learned a trick, but it seems useless.
TBlack2006-8-14 solved at, thanks.
Window. Hutia = BB; what does it mean?
To upstairs: many functions in vbs are very useful and can be called here.

Syntax:
Window.exe cscript (sexpression, slanguage) // expression can be the encrypted code of M $ script encoder.

Parameters:
Sexpression: required. String ). Code to be executed.
Slanguage: required. String ). Specifies the language of the code to be executed. The default value is Microsoft JScript [/watermark].
------------------------------------------------------------------------------ Similar discussions with 4:

Why is onblur () Not focused? FF is normal. If IE is abnormal, you can consider a delay of some time to execute focus ()
 
  2 # Large Medium SmallPosted onView the author only<HTML> <pead> <title> test </title> <br/> <SCRIPT type = "text/JavaScript"> <br/> <! -- <Br/> function checkemail (Control) {// <! -- A script error occurs when you write it in the same line as function checkemail (Control? <Br/> var Reg =/^/W + ([-+.] /W +) * @/W + ([-.] /W + )*/. /W + ([-.] /W +)/; <br/> If (control. value! = ""&&! Reg. test (control. value) {<br/> alert ("Please enter a valid email"); <br/> control. value = ""; <br/> control. focus (); <br/> return false ;} <br/>}// --> <br/> </SCRIPT> <br/> </pead> <body> <br/> <input type = "text" Value = "" onblur = "checkemail (this) "/> <br/> <input type =" text "value =" "/> <br/> </body> </ptml> <br/>
Tip: you can modify some code before running

My firefox version is 1.0.6.
IE testing is unavailable for the time being ..

Change control. Focus ();:
SetTimeout ('control. Focus () ', 100)

 
 
 <HTML> <pead> <title> test </title> <br/> <SCRIPT type = "text/JavaScript"> <br/> <! -- Function checkemail (Control) {<br/> var Reg =/^/W + ([-+.] /W +) * @/W + ([-.] /W + )*/. /W + ([-.] /W +) * $/; <br/> If (control. value! = ""&&! Reg. test (control. value) {<br/> alert ("Please enter a valid email"); <br/> control. value = ""; <br/> window. hutia = control; <br/> setTimeout ("window. hutia. focus (); ", 100); <br/> return false ;}} // --> <br/> </SCRIPT> <br/> </pead> <br/> <body> <br/> <input type = "text" value = "" onblur = "checkemail (this) "/> <br/> <input type =" text "value =" "/> </body> </ptml> <br/>
Tip: you can modify some code before running

 

  Will the moderator explain it?
Why put it in a window?
 
Save object pointer with global variables
When setTimeout is started, the life cycle of the function checkemail has ended, and the variable control in the function does not exist.

 

Why can I still use control after setTimeout?
(I have not tried ff1.0.x or IE)
 

<HTML>
<Head>
<Title> new document </title>
</Head>
<Body>
<Input type = "text" onblur = chk (this)> <br>
<Input type = "text" onblur = chk (this)>
<SCRIPT>
Function chk (bb ){
Window. Hutia = BB;
ExecScript ("n = msgbox (window. Hutia. Value, 35, 'Microsoft Internet Explorer ')", "vbs ");

Alert (n); // n = 6 Yes, 7 NO, 2 cancel.
}

</SCRIPT>
</Body>
</Html>

 

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.