The use of Pseudo-protocol (javascript:) in "JavaScript" javascript

Source: Internet
Author: User

JavaScript: This particular protocol type declares that the subject of the URL is arbitrary JavaScript code, which is run by the JavaScript interpreter.

For example, the following dead link:

<href= "javascript:void (0)">No response link</A  >

The way to add JavaScript code to the client is to place it in the URL of the pseudo-protocol description symbol javascript: Post. This particular protocol type declares that the subject of the URL is arbitrary JavaScript code, which is run by the JavaScript interpreter. If the JavaScript code in Javascript:url contains multiple statements, you must separate the statements with semicolons. Such URLs are as follows:

Javascript:var now =new Date (); " < H1 > This time:</H1>"+now;

When the browser loads such a URL, it executes the JavaScript code contained in the URL and displays the string value of the last JavaScript statement as the content of the new document. This string can contain HTML tags and be formatted exactly like other document types loaded into the browser. JavaScript URLs can also perform actions only, but do not reverse the JavaScript statements. For example:

Javascript:alert ("Hello World")

When this URL is loaded, the browser executes only the JavaScript code in it, but because there is no value to display as a new document, it does not change the currently displayed document.

Usually we want to use Javascript:url to execute some JavaScript code that does not change the currently displayed document. To do this, you must ensure that the last statement in the URL does not have a return value. One way is to specify the return value as undefined with the void operator, just use the statement void 0 at the end of Javascript:url. For example: The following URL opens a new, empty browser window without changing the current window's class capacity:

Javascript:window.open ("About:blank"); void 0;

If the URL does not have a URL run, the return value of the window.open () method will be converted to a string and displayed, and the current window will be overwritten by the following document.

I'll check the original.

The use of Pseudo-protocol (javascript:) in "JavaScript" javascript

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.