Home  >  Article  >  Web Front-end  >  Introduction to BOM in JavaScript (code example)

Introduction to BOM in JavaScript (code example)

不言
不言forward
2019-03-05 14:34:002557browse

This article brings you an introduction to BOM in JavaScript (code examples). It has certain reference value. If necessary, Friends can refer to it, I hope it will be helpful to you.

BOM refers to the browser object model, which can operate the browser through js.
window - The entire browser window is also the global object of the web page
navigator - Browser information
location - Browser address bar information, you can obtain the address or operate
history - Browser history record of this object Specific history records cannot be obtained, and the browser can only be operated forward or backward.
screen - Get information about the monitor screen currently used by the user

navigator can get the browser information, navigator.userAgent can get the current browser, and the string you get can be judged by regular rules to determine whether it is Google. Or Firefox, etc., but IE11 cannot judge it, but IE can judge it through IE's unique attribute ActiveXObject.
	  var userAgent = navigator.userAgent;
        if (/firefox/i.test(userAgent)) {
            alert("你是火狐");
        } else if (/chrome/i.test(userAgent)) {
            alert("你是chrome");
        } else if("ActiveXObject" in window){
            alert("你是ie");
        }
history History record
history.forward() is like jumping forward, history.back() is like jumping backward, history.go (parameter), history.go(1) is equivalent to history.forward();
	  var next=document.getElementById("next");
       var prev=document.getElementById("prev");
       next.onclick=function(){
        // history.forward();
        history.go(1);
       }
       
       prev.addEventListener("click",function(){
        //    history.back();
        history.go(2);
       },false)
  • loaction can obtain the current address bar information, jump address, refresh address, etc.
  • Current address:
    location.href.
  • Jump:
    1.location="http://www.baidu.com";
    2. location .assign(“http://www.baidu.com”);
    3.location.replace(“http://www.baidu.com”); //Replacement, cannot go back
  • Refresh:
    location.reload(true); // Add true to force the form to be cleared, otherwise it will only refresh the page without clearing the form.


The above is the detailed content of Introduction to BOM in JavaScript (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete