Writing Web applications using VBScript and JScript (a) flops one, gather or see:-(

Source: Internet
Author: User
Tags define iis client
js|jscript|vbscript|web| programs use VBScript and JScript to write Web applications

My heart is flying

The motivation to write this article is to see the discussion of VBScript and JavaScript, as well as another piece of similar articles, feel the need to put together the idea of the:-), and the work I produced some of the experience out and share with you, hope to help. Of course, the level is limited, mistakes are unavoidable.


Active Server pages is an important part of Microsoft's Windows DNA, and we can easily construct powerful web-based applications using ASP. There are a number of scripting languages available for ASP authoring, such as VBScript, JavaScript, Perl, and Rexx, and you can choose from several scripting languages. In this article, we discuss two scripting languages offered by Microsoft:
VBScript
Jscript

First of all, I would like to discuss:

When to use VBScript and JScript, and the difference between the two

VBScript is a subset of Visual Basic, the full name of Microsoft Visual Basic Scripting Edition. If you've ever used Visual Basic or Visual Basic for Applications (VBA), you'll find it very familiar. But they're not exactly the same, because VBScript is designed specifically for working on the web.

JScript is a Microsoft version of ECMAScript and is a set of standard definitions that include JScript and JavaScript scripting languages. JScript is detached from a set of programming languages such as C, C + +, and Java. If you've ever used C or Java before, then the structure of JScript is very familiar to you. Even if you do not know that these languages are not related, the structure of JScript is not difficult, it is as convenient as C and Java and less complex than they are.

Microsoft provides them with an ActiveX scripting Language (ActiveX Scripting editing language) engine in Internet Explorer and Internet Information Server (IIS) ( such as Vbscript.dll, Jscript.dll).

So, when do you choose which language?
We know that for ASP development there is one of the following two scripts to write:

1 server script:
Writing server scripts for IIS in an ASP page is fine regardless of the language you use. and Microsoft's Visual InterDev support them all very well.

2 Client Script:
If you want to use VBScript in a browser script, the browser must be a version of Internet Explorer. Because VBScript may not be supported by other browsers. If you're building a public Web site and you can't predict what browsers users are using, it's a problem if VBScript can only be used for Internet Explorer.
Almost every browser that allows scripting supports JScript. Therefore, if you are writing an application for a public Web site, it is a natural choice to write client script with JScript.

Other major factors that affect your decision are:

1. Error control
In VBScript there is an on error trap to control the error condition, such as On Error Resume Next. If you're writing a server script, error control is important because the script is run unattended. JScript does not have this mechanism.

2. Format
VBScript has the ability to easily format data, numbers, and currency data. JScript does not have such a feature.

3, dynamic implementation
A very powerful feature of JScript is that it allows you to dynamically build and execute Scripts (eval () functions, execscript () methods, and so on) within your scripts. In short, you can write scripts in your script. This feature is useful when you work with DHTML, because you can dynamically manipulate the DHTML document model. VBScript does not have this feature. For example, in the JavaScript of the client you can use syntax like this:

Execscript ("On Error Resume Next:object.execWB 4, 1", "VBScript");

4. Object-oriented
JScript uses a prototype-based object structure that allows you to define objects in a script. You can add methods and attributes to the object's prototype and extend the built-in objects and custom objects. For example:

Custom Object MyObject
function MyObject () {
Custom properties
This.properties1=value; The assignment is the default value for this property at this time
This.properties2;
...
Custom Methods
THIS.MYMETHOD1=METHOD1;
THIS.MYMETHOD2=METHOD2;
}

function Method1 (ARG) {
Block
}

function Method2 (ARG) {
Block
}

Especially useful is that the object can be passed back to the client through SOM, making the ASP programming way more like the previous C/s structure. (I'll probably write an in-depth discussion of SOM in the near future, and discuss the method in detail)

5. Event Control
It is convenient to use VBScript to control events in Internet Explorer, as in Visual Basic. An implied event handler can also be created in VBScript, which only requires the use of an object event structure to define a feature, such as an implicit invocation of Button1_onclick. However, in Internet Explorer, JScript does not have this feature (but this feature is supported on other JScript hosts).
Using JScript to control events in Internet Explorer will require you to link to an object that is connected to an event handler. Typically, you can specify its properties in the label bar of an object that identifies the event and has a handler function. As shown below:

<script Id=clienteventhandlersjs language=javascript>
<!--

function Button1_onclick () {
Alert ("Button1 clicked")
}

-->
</SCRIPT>
<input type= "button" value= "button" Id=button1 name=button1 language=javascript onclick= "return Button1_onclick ()" >

Or use a syntax similar to the following:
<script Id=clienteventhandlersjs language=javascript>
<!--
function Window_onload () {
Block;
}
-->
</SCRIPT>
<script Language=javascript For=window event=onload>
<!--
Window_onload ()
-->
</SCRIPT>

Notably, the Language property is set to "Javascript" in the previous example. Internet Explorer knows about the two names "JScript" and "JavaScript," but many other browsers only know "JavaScript" and don't Know "JScript." Therefore, for the sake of insurance, if you are not sure that the Web page is browsing using Internet Explorer, it is best to use "Javascript".

(To be continued)
My heart is flying



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.