Detailed BOM in JS

Detailed BOM in JS

Introduction to BOM

We JavaScript talked JavaScript in three parts this blog:

  1. ECMAScript standard (basic syntax)
  2. DOM: Document Object Model Document Object Model, which manipulates page elements
  3. BOM:Browser Object Model browser object model, operating the browser

We have already learned the first two, and today we enter the BOM module learning!

  • BOM is the browser object model
  • BOM provides some object interfaces that are independent of content pages and browser windows for interaction
  • The core of the BOM is the window object, so the window can generally be omitted when writing.
  • BOM is actually composed of a series of related objects, and each object provides many methods and properties

Top-level objects in the BOM

The window object is the top-level object of the browser and has a dual role

  1. The window object is an interface for JS to access the browser window
  2. The window object is a global object, all global variables declared, global method functions are ultimately the properties or methods of the window object

Other window methods

window object effect
window.open() Open new window
window.close() Close the current window
window.moveTo() Move current window
window.resizeTo() Adjust the size of the current window

JavaScript Window Screen

Screen object effect
screen.availWidth Available screen width
screen.availHeight Available screen height

JavaScript Window Location

Location object effect
location.href Returns the URL of the current page
location.hostname Returns the domain name of the web host
location.pathname Return the path and file name of the current page
location.port Returns the port of the web host (80 or 443)
location.protocol Returns the web protocol used (http:// or https://)
location.hash Return the fragment, the content after # in the URL
location.search Return parameters, URL parameters refer to the parameters after the URL in the URL address?
location.assign() Like href, you can jump to the page, redirect and jump
location.replace() Replace the current page, not recorded in the history, so you cannot go back to the page
location.reload() Reload the page, equivalent to refresh button, if the parameter is true, equivalent to forced refresh

JavaScript Window History

  • The window object is a history object provided by the browser to interact with the browser's history. In order to protect user privacy, the method of JavaScript accessing this object is restricted.
History object effect
history.back() Same as clicking the back button in the browser
history.forward() Same as clicking the button forward in the browser
history.go (parameter) Forward and backward function, if the parameter is 1 to go forward one page, if it is -1 to go back one page, if it is N, go forward or backward N pages

JavaScript Window Navigator

  • The Navigator object mainly records information about the browser.
Navigator object effect
window.navigator.userAgent UserAgent can determine the type of user browser
window.navigator.platform The platform can be used to determine the system platform type of the browser

Guess you like

Origin blog.csdn.net/XVJINHUA954/article/details/111996325