麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發 > JavaScript > 正文

JavaScript的BOM

2020-03-24 19:03:37
字體:
來源:轉載
供稿:網友
這次給大家帶來JavaScript的BOM,使用JavaScript的BOM的注意事項有哪些,下面就是實戰案例,一起來看一下。

location對象
location對象提供了與當前窗口中加載的文檔有關的信息,還提供了一些
導航的功能,它既是window對象的屬性,也是document對象的屬性。
語法:location.href
功能:返回當前加載頁面的完整URL
說明:location.href與window.location.href等價
語法:location.hash
功能:返回URL中的hash(#號后跟零或多個字符),如果不包含則返回空字符串
語法:location.host
功能:返回服務器名稱和端口號(如果有)
語法:locationhostname
功能:返回不帶端口號的服務器名稱。
語法:location.pathname
功能:返回URL中的目錄和(或)文件名。
語法:location.port
功能:返回URL中指定的端口號,如果沒有,返回空字符串。
語法:location.protocol
功能:返回頁面使用的協議
語法:location.search
功能:返回URL的查詢字符串。這個字符串以問號開頭。
語法:location.replace(url)
功能:重新定向URL
說明:使用location.replace不會再歷時記錄中生成新紀錄。
語法:location.reload()
功能:重新加載當前顯示的頁面。
說明:
location.reload()有肯從緩沖中加載
location.reload(true)從服務器重新加載
history對象
history對象保存了用戶在瀏覽器中訪問頁面的歷史記錄
語法:history.back()
功能:回到歷史記錄的上一步
說明:相當于使用了history.go(-1)
語法:location.forward()
功能:回到歷時記錄的下一步
說明:相當于使用了history.go(1)
語法:history.go(-n)
功能:回到歷時記錄的前n步
語法:history.go(n)
功能:回到歷史記錄的后n步
navigator對象
useragent:用來識別瀏覽器名稱,版本,引擎以及操作系統等信息的內容。
screen對象
語法:screen.availWidth
功能:返回可用的屏幕寬度
語法:screen.availHeight
功能:返回可用的屏幕高度

location01.html:

 !DOCTYPE html  html  head  meta charset= UTF-8  title Document /title  style type= text/css  .box1{ height: 900px; background: #ccc; .box2{ height: 500px; background-color: #333; /style  /head  body  div id= box1 /div  div /div  input type= button id= btn value= 返回頂部  script  btn.onclick = function () { location.hash = #box1  console.log(location.hash); console.log(location.href); console.log(location.hash); console.log(location.host); console.log(location.hostname); console.log(location.pathname); console.log(location.port); console.log(location.protocol); console.log(location.search); /script  /body  /html 

location02.html:

 !DOCTYPE html  html  head  meta charset= UTF-8  title Document /title  /head  body  input type= button value= 刷新 id= btn  script  /*setTimeout(function () { //location.href = https://www.baidu.com  //window.location = https://www.baidu.com  location.replace( https://www.baidu.com  },1000);*/ document.getElementById( btn ).onclick = function () { location.reload(); //location.reload(true); /script  /body  /html 

history01.html:

 !DOCTYPE html  html  head  meta charset= UTF-8  title Document /title  /head  body  a href= example_2.html example_2.html /a  input type= button value= 后退 id= btn1  input type= button value= 前進 id= btn2  script  var btn1 = document.getElementById( btn1  var btn2 = document.getElementById( btn2  btn1.onclick = function () { //history.back(); history.go(-1); btn2.onclick = function () { history.forward() //history.go(1); /script  /body  /html 

navigator.html:

 !DOCTYPE html  html  head  meta charset= UTF-8  title Document /title  /head  body  script  function getBrowser() { var explorer = navigator.userAgent.toLowerCase(); var browser =  if (explorer.indexOf( msie ) -1) { browser = IE  } else if (explorer.indexOf( chrome ) -1){ browser = Chrome  } else { browser = asdf  return browser; var msg = 您用的是 +getBrowser()+ 瀏覽器  console.log(msg); /script  /body  /html 

screen.html:

 !DOCTYPE html  html  head  meta charset= UTF-8  title Document /title  /head  body  script  console.log(screen.availWidth); console.log(screen.availHeight); console.log(window.innerWidth); console.log(window.innerHeight); /script  /body  /html 

相信看了這些案例你已經掌握了方法,更多精彩請關注php 其它相關文章!

相關閱讀:

ES6 module語法加載 import export

判斷登陸是否失效代碼

如何利用getBoundingClientRect()來實現div容器滾動固定

實現瀑布流布局的倆種方法

以上就是JavaScript的BOM的詳細內容,html教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 奶子吧naiziba.cc免费午夜片在线观看 | 欧美一级爱操视频 | 欧美日韩亚洲精品一区二区三区 | 成人毛片网站 | 在线91视频 | 19禁国产精品福利视频 | 成人三级电影网址 | 久久视频精品 | 手机视频在线播放 | 久久久资源网 | 成人在线影视 | 草草视频免费 | 777sesese| 91精品国产一区二区三区动漫 | 久久久线视频 | av电影网站在线 | 精品国产一区二区三区在线观看 | 久久亚洲视频网 | 法国极品成人h版 | 精品国产一区二区三区天美传媒 | 高清中文字幕在线 | 久久久久久久久日本理论电影 | 久久网一区二区 | 黄视频网站免费观看 | 蜜桃一本色道久久综合亚洲精品冫 | 成年人黄视频 | 91av网址| 国产宾馆3p国语对白 | 四虎久草 | 国产成人在线播放视频 | 在线播放黄色片 | 九九热精品在线播放 | 成人精品久久久 | 特一级毛片| 欧美人的天堂一区二区三区 | 在线看一区二区三区 | 8x成人在线电影 | 91精品动漫在线观看 | 色日本视频 | 男女牲高爱潮免费视频男女 | 91午夜少妇三级全黄 |