BOM operation of JavaScript learning
Introduction to BOM operation
BOM operation
Browser object modelbrowser object model
Using JS code to operate the browser
Current page operation
Current page height and width
window.innerWidth; // 982
window.innerHeight; // 722
Open website
//Open a website, the second parameter is empty, and the third parameter writes the size and position of the window
window.open("http://www.baidu.com","","height=800px width=400px");
Close current page
window.close();
Window sub object
window. navigator. appName; // Current browser location
window. navigator. userAgent; // Is it currently a browser
window. navigator. appVersion; // Current browser version
window. navigator. platform; // Currently used platform, such as Win32
History object
window. history. back(); // Back to previous page
window. history. forward(); // Go to the next page
Location object
window. location; // Get object
window. location. href; // Current web address
window. location. href = " http://www.baidu.com "; // assign a value and jump to the web address
window. location. reload(); // Refresh page
Spring frame
Warning box
alert("asd");
Confirmation box
confirm(123);
prompt box
Prompt ("give me Kangkang", "Altman");
Enter nothing:
Input:
Timer related
Triggered in a few seconds
function fun1() {
Alter ("trigger after three seconds");
}
setTimeout(fun1, 3000);
//If you want to clear a scheduled task
// let t = setTimeout(fun1, 3000);
// clearTimeout(t);
The cycle is triggered after a period of time
function fun2() {
Alert ("Altman");
}
// setInterval(func2, 3000);
//Repeat the pop-up warning box every three seconds within nine seconds
function fun3() {
let t = setInterval(fun2, 3000);
function inner() {
clearInterval(t);
}
setTimeout(inner, 9000);
}
fun3();