当前位置:网站首页>BOM - location, history, pop-up box, timing

BOM - location, history, pop-up box, timing

2022-07-06 04:11:00 Sugar ^o^

One 、History
  1. Window History Back

history.back() Method loads the previous... In the history list URL. It is equivalent to clicking the back button in the browser .

  1. Window History Forward

history forward() Method loads the next in the history list URL. Equivalent to clicking the forward button in the browser .

Two 、 pop-up
  1. Warning box

If you want to ensure that information is passed to users , Warning boxes are usually used .

When the warning box pops up , The user will need to click “ determine ” Come on .

window.alert(“sometext”); window.alert() The method can be without window Prefix to write .

  1. Confirmation box

If you want users to verify or accept something , Usually use “ confirm ” box .

When the confirmation box pops up , Users will have to click “ determine ” or “ Cancel ” To carry on .

If the user clicks “ determine ”, This box returns true. If the user clicks “ Cancel ”, This box returns false.

grammar window.confirm(“sometext”);
window.confirm() The method can be without window Prefix to write .

  1. Prompt box

If you want the user to enter a value before entering the page , Usually use the prompt box .

When the prompt box pops up , The user will have to enter a value and click “ determine ” Or click on “ Cancel ” To carry on .

If the user clicks “ determine ”, This box returns the entered value . If the user clicks “ Cancel ”, This box returns NULL.

window.prompt(“sometext”,“defaultText”);
window.prompt() The method can be without window Prefix to write .

3、 ... and 、Timing
  1. setTimeout() Method

    window.setTimeout(function, milliseconds);
    
    window.setTimeout()  The method can be without  window  Prefix to write .
    

    The first parameter is the function to execute .
    The second parameter indicates the number of milliseconds before execution
    .

clearTimeout() Method stops execution setTimeout() Functions specified in .

window.clearTimeout(timeoutVariable)

  1. setInterval() Method

setInterval() Method repeats a given function at each given time interval .

window.setInterval(function, milliseconds);
window.setInterval()  The method can be without  window  Prefix to write .

The first parameter is the function to execute .
The second parameter is the length of the time interval between each execution .

clearInterval() Method stop setInterval() Method .

window.clearInterval(timerVariable)

Four 、Location
  1. Window Location Href

window.location.href Property to return the URL.

document.getElementById(“demo”).innerHTML = " Page location is " + window.location.href;

  1. Window Location Host name

window.location.hostname Property returns ( Current page ) The Internet host The name of .

document.getElementById(“demo”).innerHTML = " The page hostname is " +
window.location.hostname;

  1. Window Location Pathname

window.location.pathname Property to return the Pathname .

  1. window.location.protocol Property to return to web agreement

  2. window.location.port Property returns ( Current page ) The number of the Internet host port .

  3. window.location.assign() Method to load a new document .

原网站

版权声明
本文为[Sugar ^o^]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202132243019492.html