当前位置:网站首页>Detailed explanation of various objects in browser object

Detailed explanation of various objects in browser object

2022-06-11 23:32:00 A-linWeb

window object Represents an open window in the browser .

alert() pop-up
confirm() Confirmation box
prompt () The text box

Various boxes Test code usage Formal projects are not recommended Because they block the code Various plug-in libraries are recommended

navigator object That is, it contains information about the browser

navigator.platform: Type of operating system ;
navigator.userAgent: Browser set User - Agent character string .
navigator.appCodeName: Browser code ;
navigator.appName: Browser name ;
navigator.appVersion: Browser version ;
navigator.language: Language for browser settings ;
navigator.systemLanguage: Browser system language ;
navigator.cookieEnabled: Whether the browser is enabled cookie

console.log(navigator.userAgent); // Can be used to determine the browser
console.log(navigator.language); // Browser language .
console.log(navigator.systemLanguage); // The language of the operating system .

location object Contains information about the current URL Information about

location.href // Get the complete url Information
location.protocol // obtain url Agreement name in http:
location.host // obtain url Host name in With port number ip Address / domain name
location.hostname // obtain url Host name in No port number
location.pathname // obtain url In the path File location
location.search // obtain url The query string in
location.hash // obtain url Fragments in
location.port // Get the port number
Important methods
Refresh
1.location.reload();// Reload page , Refresh the page , Equivalent to pressing f5
2. location.href = location.href // location.href It is essentially used to jump to another URL Address Can be used to refresh
3.location.assign()//location.assign() Assign a new value to the address Can be used to jump It can also be used to step back
4. location.replace() // location.replace() Can be used to jump But you can't go back

history object The history object is mainly used for advancing between pages , Backward operation

history.back()
history.forward()
history.go()
"history.go(1)" Take a step forward
"history.go(2)" Two steps forward

history.replaceState(“ Add data , It can be a basic type , It can also be a reference type ”, “ title ”, “two.html”); // You can also perform jump operations ( Only modified url Address , No jump ), History will not be added during jump . Can't go forward or backward

history.pushState(“ Add data , It can be a basic type , It can also be a reference type ”, “ title ”, “two.html”); // You can also perform jump operations ( Only modified url Address , No jump ), History will be added during jump .

screen object Contains information about the client display screen .

window.screen.availWidth
window.screen.availHeight

原网站

版权声明
本文为[A-linWeb]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011608548301.html