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

Introduction to BOM in JavaScript (code example)

不言
Release: 2019-03-05 14:34:00
forward
2492 people have browsed it

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");
        }
Copy after login
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)
Copy after login
  • 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!

Related labels:
source:csdn.net
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!