Home >Web Front-end >JS Tutorial >Common Bom objects in JS

Common Bom objects in JS

一个新手
一个新手Original
2017-10-20 09:59:352161browse

BOM (Browser Object Mode) browser object model is an important part of Javascript. It provides a series of objects for interacting with the browser window. These objects are often collectively referred to as the BOM.

Let’s take a look at the picture first

1. Window object - BOM core

window, as the name suggests , window object. It represents the entire browser window and is mainly used to operate the browser window. At the same time, the window object is also a Global object in ECMAScript, so all global variables and functions are its properties, and all native constructors and other functions also exist in its namespace.

Methods of the pop-up box class. Omit the window

     alert('提示信息')
    confirm("确认信息")
    prompt("弹出输入框")
    open("url地址",“_black或_self”,“新窗口的大小”)
    close()  关闭当前的网页

timer in front and clear the timer.

    setTimeout(函数,时间) 只执行一次
    clearTimeout(定时器名称) 清除定时器,用于停止执行setTimeout()方法的函数代码。
    setInterval(函数,时间) 无限执行
    clearInterval() 方法用于停止 setInterval() 方法执行的函数代码。

 Cookies are used to store user information on web pages.

JavaScript can use the document.cookie attribute to create, read, and delete cookies. document.cookie will return all cookies in the form of strings, type format: cookie1=value; cookie2=value; cookie3=value;

2. Document object

It is an attribute of the window object and can be used to process page documents

3. The location object

object is used to obtain the address (URL) of the current page, and Redirect the browser to a new page.

 window.location The object does not need to use the window prefix when writing. Some examples:

  location.herf = 'url地址'
  location.hostname 返回 web 主机的域名
  location.pathname 返回当前页面的路径和文件名
  location.port 返回 web 主机的端口 (80 或 443)
  location.portocol 返回页面使用的web协议。 http:或https:

4. Navigator object

The object provides information related to the browser. userAgent is the most commonly used attribute and is used to complete browser judgment.

 window.navigator The object does not need to use the window prefix when writing.

5. The screen object

is mainly used to obtain the user's screen information.

  window.screen对象在编写时可以不使用 window 这个前缀
  height: 获取整个屏幕的高。
  width : 获取整个屏幕的宽。
  availHeight: 整个屏幕的高减去系统部件的高( 可用的屏幕宽度 )
  availWidth : 整个屏幕的宽减去系统部件的宽(可用的屏幕高度 )

6. History object

The object contains the history of the browser.

  window.history对象在编写时可不使用 window 这个前缀。
  back() 返回上一页。
  forward() 返回下一页。
  go(“参数”) -1表示上一页,1表示下一页。

The above is the detailed content of Common Bom objects in JS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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