Javascript: This special protocol type declares that the URL subject is any javascript code, the method for adding javascript code to the client by running the javascript interpreter is to place it in the URL after the pseudo-Protocol interpreter javascript. This special protocol type declares that the subject of the URL is any javascript code, which is run by the javascript interpreter. If javascript: the javascript code in the URL contains multiple statements, you must use semicolons to separate these statements. The URL is as follows:
javascript:var now = new Date(); "The time is:" + now;
When the browser loads such a URL, it will execute the javascript code contained in the URL and display the string value of the last javascript statement as the content of the new document. This string value can contain HTML tags and be formatted. It is displayed exactly the same as other documents loaded into the browser.
Javascript URLs can also contain javascript statements that only execute actions but do not return values. For example:
javascript:alert("hello world!")
When such a URL is loaded, the browser only executes the javascript code in it, but it does not change the currently displayed document because it is not displayed as a value for the new document.
We usually want to use javascript: URL to execute some javascript code that does not change the currently displayed document. To do this, make sure that the last statement in the URL does not return a value. One way is to explicitly specify the return value as underfined using the void operator. You only need to use the void 0 statement at the end of javascript: URL. For example, the following URL opens a new blank browser window without changing the content of the current window:
javascript:window.open("about:blank"); void 0;
If the URL does not have the void operator, the return value of the window. open () method is converted to a string and displayed. The current window is overwritten by the following document.