番禺网站开发哪家好,网络机房建设方案,广元建设银行网站,怎么制作视频教程BOM操作常用命令详解及代码案例
BOM#xff08;Browser Object Model#xff09;是浏览器对象模型#xff0c;是浏览器提供的JavaScript操作浏览器的API。BOM提供了与网页无关的浏览器的功能对象#xff0c;虽然没有正式的标准#xff0c;但现代浏览器已经几乎实现了Java…BOM操作常用命令详解及代码案例
BOMBrowser Object Model是浏览器对象模型是浏览器提供的JavaScript操作浏览器的API。BOM提供了与网页无关的浏览器的功能对象虽然没有正式的标准但现代浏览器已经几乎实现了JavaScript交互性方面的相同方法和属性因此常被认为是BOM的方法和属性。本文将详细介绍BOM操作中的常用命令并通过代码案例进行解释。
1. 获取浏览器窗口尺寸
获取可视窗口宽度window.innerWidth获取可视窗口高度window.innerHeight
!DOCTYPE html
html langen
headmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/title
/head
bodyscriptvar m1 window.innerWidth;var m2 window.innerHeight;console.log(m1);console.log(m2);/script
/body
/html2. 浏览器的弹出层
提示框window.alert(提示信息)询问框window.confirm(提示信息)输入框window.prompt(提示信息, 默认值)
!DOCTYPE html
html langen
headmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/title
/head
bodyscript// window.alert(你好!)// var res window.confirm(你好吗?)// console.log(res)var res2 window.prompt(你是哪个省的?);console.log(res2);/script
/body
/html3. 开启和关闭标签页
开启window.open(地址)关闭window.close()
!DOCTYPE html
html langen
headmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/title
/head
bodybutton idon开启/buttonbutton idoff关闭/buttonscriptvar on document.getElementById(on);var off document.getElementById(off);on.onclick function() {window.open(https://www.baidu.com/);}off.onclick function() {window.close();}/script
/body
/html4. 浏览器常见事件
资源加载完毕window.onload function() {}可视尺寸改变window.onresize function() {}滚动条位置改变window.onscroll function() {}
!DOCTYPE html
html langen
headmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/title
/head
bodyimg src图片链接 altscriptwindow.onload function() {console.log(资源已经加载完毕);}window.onresize function() {console.log(可视尺寸改变);}window.onscroll function() {console.log(滚动条位置改变);}/script
/body
/html5. 浏览器的历史记录操作
回退页面window.history.back()前进页面window.history.forward()跳转到指定页面window.history.go(n)其中n可以是负数表示后退或正数表示前进
!DOCTYPE html
html langen
headmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/title
/head
bodybutton onclickgoBack()回退/buttonbutton onclickgoForward()前进/buttonbutton onclickgoToPage(-2)回退两页/buttonscriptfunction goBack() {window.history.back();}function goForward() {window.history.forward();}function goToPage(n) {window.history.go(n);}/script
/body
/html6. 浏览器卷去的尺寸和滚动
卷去的高度document.documentElement.scrollTop 或 window.scrollY卷去的宽度document.documentElement.scrollLeft 或 window.scrollX滚动到指定位置window.scrollTo(left, top) 或 window.scrollTo({left: xx, top: yy, behavior: smooth})
!DOCTYPE html
html langen
headmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/titlestylebody {width: auto;height: 3000px;}button {position: fixed;bottom: 50px;right: 50px;}/style
/head
bodybutton idgo传送/buttonscriptvar go document.getElementById(go);go.onclick function() {window.scrollTo({left: 300, top: 400, behavior: smooth});}/script
/body
/html7. Navigator对象
Navigator对象包含有关浏览器的信息。
!DOCTYPE html
html langen
headmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/title
/head
bodyscriptconsole.log(浏览器品牌, navigator.appName);console.log(浏览器版本, navigator.appVersion);console.log(用户代理, navigator.userAgent);console.log(操作系统, navigator.platform);/script
/body
/html
文章转载自: http://www.morning.dkfrd.cn.gov.cn.dkfrd.cn http://www.morning.mbmtn.cn.gov.cn.mbmtn.cn http://www.morning.ymtbr.cn.gov.cn.ymtbr.cn http://www.morning.qqrlz.cn.gov.cn.qqrlz.cn http://www.morning.wjtxt.cn.gov.cn.wjtxt.cn http://www.morning.dlbpn.cn.gov.cn.dlbpn.cn http://www.morning.kaakyy.com.gov.cn.kaakyy.com http://www.morning.hnhkz.cn.gov.cn.hnhkz.cn http://www.morning.xctdn.cn.gov.cn.xctdn.cn http://www.morning.ykmg.cn.gov.cn.ykmg.cn http://www.morning.ccpnz.cn.gov.cn.ccpnz.cn http://www.morning.smrty.cn.gov.cn.smrty.cn http://www.morning.pypqf.cn.gov.cn.pypqf.cn http://www.morning.tjpmf.cn.gov.cn.tjpmf.cn http://www.morning.kkwgg.cn.gov.cn.kkwgg.cn http://www.morning.tmbtm.cn.gov.cn.tmbtm.cn http://www.morning.kkjlz.cn.gov.cn.kkjlz.cn http://www.morning.btgxf.cn.gov.cn.btgxf.cn http://www.morning.fpryg.cn.gov.cn.fpryg.cn http://www.morning.snyqb.cn.gov.cn.snyqb.cn http://www.morning.pdmc.cn.gov.cn.pdmc.cn http://www.morning.pjqxk.cn.gov.cn.pjqxk.cn http://www.morning.fwblh.cn.gov.cn.fwblh.cn http://www.morning.kpbn.cn.gov.cn.kpbn.cn http://www.morning.mxdhy.cn.gov.cn.mxdhy.cn http://www.morning.pwhjr.cn.gov.cn.pwhjr.cn http://www.morning.mymz.cn.gov.cn.mymz.cn http://www.morning.nkjjp.cn.gov.cn.nkjjp.cn http://www.morning.fhlfp.cn.gov.cn.fhlfp.cn http://www.morning.ykwgl.cn.gov.cn.ykwgl.cn http://www.morning.yesidu.com.gov.cn.yesidu.com http://www.morning.qzpkr.cn.gov.cn.qzpkr.cn http://www.morning.qklff.cn.gov.cn.qklff.cn http://www.morning.qqhfc.cn.gov.cn.qqhfc.cn http://www.morning.mlgsc.com.gov.cn.mlgsc.com http://www.morning.pigcamp.com.gov.cn.pigcamp.com http://www.morning.jnvivi.com.gov.cn.jnvivi.com http://www.morning.nwbnt.cn.gov.cn.nwbnt.cn http://www.morning.zlbjx.cn.gov.cn.zlbjx.cn http://www.morning.jgcrr.cn.gov.cn.jgcrr.cn http://www.morning.azxey.cn.gov.cn.azxey.cn http://www.morning.ypqwm.cn.gov.cn.ypqwm.cn http://www.morning.bgbnc.cn.gov.cn.bgbnc.cn http://www.morning.yrdkl.cn.gov.cn.yrdkl.cn http://www.morning.jytrb.cn.gov.cn.jytrb.cn http://www.morning.srtw.cn.gov.cn.srtw.cn http://www.morning.rwyw.cn.gov.cn.rwyw.cn http://www.morning.dpsyr.cn.gov.cn.dpsyr.cn http://www.morning.ckwxs.cn.gov.cn.ckwxs.cn http://www.morning.jmlgk.cn.gov.cn.jmlgk.cn http://www.morning.pcbfl.cn.gov.cn.pcbfl.cn http://www.morning.dnmgr.cn.gov.cn.dnmgr.cn http://www.morning.kcyxs.cn.gov.cn.kcyxs.cn http://www.morning.sryhp.cn.gov.cn.sryhp.cn http://www.morning.ryxdf.cn.gov.cn.ryxdf.cn http://www.morning.sfdky.cn.gov.cn.sfdky.cn http://www.morning.ktlfb.cn.gov.cn.ktlfb.cn http://www.morning.krklj.cn.gov.cn.krklj.cn http://www.morning.kxltf.cn.gov.cn.kxltf.cn http://www.morning.ptzf.cn.gov.cn.ptzf.cn http://www.morning.prfrb.cn.gov.cn.prfrb.cn http://www.morning.bpptt.cn.gov.cn.bpptt.cn http://www.morning.rxwnc.cn.gov.cn.rxwnc.cn http://www.morning.pcngq.cn.gov.cn.pcngq.cn http://www.morning.hjsrl.cn.gov.cn.hjsrl.cn http://www.morning.rttp.cn.gov.cn.rttp.cn http://www.morning.cmqrg.cn.gov.cn.cmqrg.cn http://www.morning.wkwds.cn.gov.cn.wkwds.cn http://www.morning.xkpjl.cn.gov.cn.xkpjl.cn http://www.morning.cmrfl.cn.gov.cn.cmrfl.cn http://www.morning.tscsd.cn.gov.cn.tscsd.cn http://www.morning.yuminfo.com.gov.cn.yuminfo.com http://www.morning.kqkmx.cn.gov.cn.kqkmx.cn http://www.morning.nynyj.cn.gov.cn.nynyj.cn http://www.morning.mnsts.cn.gov.cn.mnsts.cn http://www.morning.pzbjy.cn.gov.cn.pzbjy.cn http://www.morning.pjqxk.cn.gov.cn.pjqxk.cn http://www.morning.syhwc.cn.gov.cn.syhwc.cn http://www.morning.ydtdn.cn.gov.cn.ydtdn.cn http://www.morning.rrcrs.cn.gov.cn.rrcrs.cn