前端面经 实用的BOM属性对象方法
location 对象
-
location.href
返回或用于设置当前文档的url ——https://developer.mozilla.org/zh-CN/docs/Web/API/Location
-
location.search
返回URL 中的查询字符串部分例如:当前的url为
https://developer.mozilla.org/zh-CN/docs/Web/API/Location?a=1&b=2
location.search
为'?a=1&b=2'
-
location.hash
返回URL#后面的内容,如果没有#,返回空例如:当前的url为
https://developer.mozilla.org/zh-CN/docs/Web/API/Location#search-results-close-container
location.hash
为#search-results-close-container
-
loaction.host
返回URL 中的域名部分例如:当前的url为
https://developer.mozilla.org/zh-CN/docs/Web/API/Location
location.host
为developer.mozilla.org
-
location.pathname
返回URL 的域名后的部分例如:当前的url为
https://developer.mozilla.org/zh-CN/docs/Web/API/Location
location.pathname
为'/zh-CN/docs/Web/API/Location'
-
loaction.port
返回URL 中的端口部分例如:当前的url为
https://developer.mozilla.org/zh-CN/docs/Web/API/Location
location.port
为''
-
location.protocol
返回URL 中的协议部分返回
http:
或https:
等 -
location.assign(url)
设置当前文档的URL -
location.replace(url)
用给定的 URL 替换掉当前的资源。与 assign() 方法不同的是用 replace()替换的新页面不会被保存在会话的历史 History中,这意味着用户将不能用后退按钮转到该页面 -
location.reload()
重载当前页
history对象
history.go(num)
前进或后退指定页数history.back()
后退一页history.forward
前进一页
Navigator
navigator.userAgent
返回用户代理头的字符串(就是包含浏览器版本信息等的字符串)navigator.cookieEnabled
返回浏览器是否支持(启用)cookie