Home > Web Front-end > JS Tutorial > body text

JavaScript Window Function Guide: Writing Content in the Window_Javascript Tips

WBOY
Release: 2016-05-16 19:27:46
Original
1140 people have browsed it

The window.open() method opens a new window, and the document.open() method opens a new document, in which you can use the write() or writeln() method to write content. Its syntax is:
oNewDoc = document.open (sMimeType[, sReplace]);
sMineType is a string that defines the MIME type. Navigator supports several different MIME types, but Internet Explorer currently only supports "text/html". The sMineType parameter is optional. The second parameter is also a string, which defines whether the new document being written should replace the current document's position in the history. If you want to achieve replacement, use the string "replace".
"replace" is basically used for windows that have empty documents or "about:blank" URLs. After "replace" is defined, the write() method can create HTML content in this window and replace the current URL's position in the history. If "replace" is not defined, the created HTML has its own historical position, and the user can click the back button to move forward until it is empty.
Look at the following script snippet:
var oNewDoc = document.open("text/html", "replace");
var sMarkup = "";
sMarkup = "Hello, world!
Return< ;/BODY>";
oNewDoc.write(sMarkup);
oNewDoc.close();
As you can see, we included a link in the new document, so you You can return to this page. If you click the browser's back button, the browser returns to the page before this page. Because we used the "replace" parameter, the new document (the document being written) replaces the current document's position in the history, so clicking the back button will not return to the current page (the page containing the script). The button below executes the same script, but without the "replace" parameter, so you can return to this page by clicking your browser's back button.
The following is the source code of this button:


[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template