The composition of js

js specification
DOM is a set of APIs for operating pages.
BOM is a set of APIs for operating browser pages.
Window navigator screen history location
window Object: Browser window
features:
1. For global variables or global methods, when value or call , You can omit
the top-level object in js when 2.window object (all global variables, global functions, including document are properties of window)
3.window object has a default property name, and the value of name can only be a string
4. The top attribute is read-only and cannot be modified
var a = 5;
console.log (a);
console.log (window.a);
console.log (window);
console.log (age); // Report error, not The definition
window object has a default property name, and the value of name can only be the string
window.name = 5;
consol.log (name);
name = [6,7,8];
consol.log (name);
top The property is read-only and cannot be modified
consol.log (top);
var top = "abc";
consol.log (name);


Open window open
close window close
var newwindow;
document.getElementById ("open"). Onclick = function () {
open window
@ param url URL
@param nane is equivalent to the
two values of the target attribute of the a tag -self directly on this page Open-
blank opens in a new tab (default)
@param featrues Features: set the size and position of the new window
@param replace
true-url replaces the current page
in the browsing history false-url directly creates a new entry in the browsing history
newwindow = window.opent ("http://www.baidu.com", "-self", "left: 80px, top: 80px, width: 500px, height: 500px");
}
document.getElementById ("close") .onclick = function () {
Close window: use which window you want to close to call the close
method
newWindow.close ()
}


Intra-chain writing of script: If it is written in the head, you will not be able to get the dom element, because the js code is executed from top to bottom. At the time of interpretation, the body has not yet executed
three window events: three moments from the browser opening to closing
1. All the content of the page will be executed after it is loaded (including the dom element of the page, external resources, and image resources)
window.onload = function () {
console.log ("Loaded");
}
Function: it can be in the position of the page Get the dom element just
before the page is about to close
window.onbeforeunload = function () {
console.log ("Page is about to close");
Function: Retain the customer return "Are you sure you want to leave?"
Virus: When closing the page, artificial Write an infinite loop, open a new window wirelessly (not recommended to write, because it will cause the computer to freeze, etc.)
while (true) {
window.open ();

}
} The
page is closing, unable to do anything
window.onunload = function () {
console.log ("Page is closing");
}

Guess you like

Origin www.cnblogs.com/zycs/p/12683964.html