Debugging Javascript/vbscript script (ie article) _ Related skills

Source: Internet
Author: User

In both ways, you can use Visual Studio for debugging, and first look at the debugging of Web script programs that you use more frequently:
1. To debug the script inside the Web page, the debugger needs to host the program-here is IE support, in fact all of the script interpreter implements a COM debugging interface. By querying this interface of the interpreter, the debugger can set breakpoints, query variables, and catch exceptions, and of course, the query to this interface requires the host program to agree ... As for how to implement this interface, we will talk about it in later articles.
2. By default, IE is the Script debugging support feature turned off, so you need to show it to open it. Open IE, click "Tools"-"Internet Options", select Advanced tab in "Internet Options", and in the "Settings" list, find the "Disable scripting (Internet Explorer)" option, which is checked out by default-hook it up.

3. Use IE to open a new Web page, whether it is a remote, or local (open from the local hard drive) page. For example, one of the following pages, save as test.html:

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
<title>javascript Debugging </title>
<script language=javascript>
function onload () {
var test = unescape ("http://www.google.com");
alert (test);
}
</script>
<body onload= "onload ()" >
</body>

4. Start Visual Studio and click the "Tools"-"Attach to process" menu in the VS menu to open the "Attach to process" window. Visual Studio actually supports a variety of debugging modes, debugging C + + (native) programs, and debugging. NET (Managed) programs, debug scripts, debug Silverlight programs, and debug SQL stored procedures. By default, Visual Studio chooses the most appropriate debug mode based on the additional process type, but sometimes you need to set it manually. For example, Internet Explorer this program, IE can run multiple seed programs, ie itself and ActiveX control is c++/c written, ie can run the WINFORM/WPF program, IE can run Silverlight program, of course, The most common IE is running javascript/vb script scripts. Visual Studio is always confused by IE when attaching to the Internet Explorer process, so we need to manually tell Visual Studio what debug mode we want to use.
In the Attach to process window, in the "Attach To ..." (English is attach to ...) text box next to the "Select" button, in the pop-up "Select Code Type" window, check the "debug the following types", and select "Script." As shown in the following illustration:

5. Then you need to select the process to attach in the "Attach to process" window, and in the "Available Processes" (Available processes) list, there is a "type" column that lists the debugging modes supported by the corresponding process, such as you can see in the above diagram, Several iexplore.exe support scripts and C + + Debug mode (script, x86). So all you have to do is find the process of executing the Web page, where I chose the iexplore.exe with ID 3732, because that's the process of running the third step of the page. Finally, click the "Attach" button to debug the specified IE process using script debug mode (Attach).
Note: A careful netizen may see that the title of Iexplore.exe with ID 1692 is "javascript debugging"-corresponding to the browser process ID where we execute the Web page. In fact, before IE 8, the choice of the browser process to perform the Web page is generally based on the title of the browser, but there are some changes in IE 8, this change in the article will be mentioned.
6. Attach up, in the 7th line of the page (page source in the third step inside) set a breakpoint-as usual debugging C # and C + + code, set up, back to the IE process, refresh the page. At this point, Visual Studio should interrupt the execution of IE on line 7th of the page, and you can view the values of the script variables in the Watch window:

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.