BOM Browser Object Model

Keywords: Windows

BOM

Abbreviation of Browser object model, Browser object model

1. Common Objects

Windows Window, browser Window

Global variables and global functions are defined using the window method

Global variables are attributes of windows and can be accessed directly by window.a.

Browser Width: window.innerWidth

Browser Height: window.innerHeight

Common methods:

Open() opens a new window with three parameters. The first address needs to write protocol; the second is the way to open it; and the third is the width of the new browser. If the first two parameters do not exist, then open is an empty window.

<body>
<button onclick="openWin()">Open a new window</button>
<button onclick="closeWin()">Close a new window</button>
<button onclick="removeWin()">Move new windows</button>
<script>
    function openWin(){
        var myWindow = window.open("http://www.runoob.com","_blank","width = 200,height = 500");
    }
</script>
</body>

Close() Closes a newly opened window

function closeWin(){
    myWindow.close();
}

MoeTo Move Window, Starting at the top left corner and focusing at the same time

function removeWin(){
    //The default location of a new window is in the upper left corner
    myWindow.moveTo(200,200);
    myWindow.focus();
}

reSizeTo Change Size

function resizeWin(){
    myWindow.resizeTo(1000,1000);
    myWindow.focus();
}

Screen screens are also objects under windows, and in use we can omit Windows.

<script>
    var scrWidth = window.screen.width;
    var scrHeight = window.screen.height;
    document.write("Width of screen" + scrWidth + "Screen height" + scrHeight);
    var scrAviWidth = screen.availWidth;
    var scrAviHeight = screen.availHeight;
    document.write("<br>");
    document.write("Width of screen" + scrAviWidth + "Screen height" + scrAviHeight);
</script>

Location: Address

Common attributes: href complete path Port port number pathName path name Protocol protocol

Open a new path

location.assign("http://runoob.com");

Refresh: Normal Refresh/Forced Refresh

location.assign("http://runoob.com");

History History

Record the current history

Back returns

Forward Next Page

Go goes to a particular page - 1 is returned

2. Bullet window

Alert (): The warning box is also a method under Windows, which can be ignored and omitted.

Prompt (): The information prompt input box is also a method under Windows. Pass in the value when the click is confirmed

Confirm (): Confirm the pop-up window, click OK, pop-up true, otherwise flash

3.Cookie

Function: Store data in a local browser, often used to remember accounts

Composition: The form of key-value pairs

Stored data: "useId=445: psd=554"

Validity: expires deadline

Store cookies: Write a string in format and assign it to document.cookie

Getting cookies: parsing cookies to get what you want

Clear cookies: Change the expiry date of stored cookies to a certain day in the past. Clear cookies.

 

4. Timer

setInterval("function", "number of milliseconds"): timer, called every time.

<body>
<p id="id"></p>
<script>
    setInterval("getTime()",1000);
    function getTime(){
        var time = new Date();
        var hour = time.getHours();
        var minute = time.getMinutes();
        var second = time.getSeconds();
        var id = document.getElementById("id");
        id.innerHTML =hour + ":" + minute + ":" + second;
    }
</script>
</body>

clearInterval(): Clear timer

How long does setTimeout() call this function, and it can only be called once; a delayer

Posted by jkeppens on Wed, 05 Jun 2019 13:28:39 -0700