BOM

BOM

Browser Object Model

  • window.history
    控制瀏覽器的前進后退
    console內(nèi)輸入,可以觀察到效果
    window.history.back()
    window.history.forward()
    window.history.go(-1) // === back()

  • window.innerHeight
    瀏覽器窗口內(nèi)容區(qū)域高度

  • window.length
    針對頁面中的iframe,有幾個長度就是幾

  • window.location
    操縱瀏覽器的刷新按鈕和地址欄
    window.location. 在當(dāng)前頁面打開百度,也可以寫成window.location = 'http://www.baidu.com'
    location.protocol 協(xié)議
    location.hostname 域名
    location.port端口
    location.host 域名加端口
    location.pathname 路徑
    location.search 返回?后面的東西
    location.hash #后面的 錨點fragment 哈希
    location.origin 協(xié)議加域名加端口

  • window.name
    a標簽內(nèi)設(shè)置target就能修改window.name

  • window.navigator
    瀏覽器的所有信息
    window.navigator.useragent 可以用來區(qū)別不同瀏覽器

  • window.screen
    屏幕相關(guān)信息
    window.screen.availHeight
    window,screen.height

  • window.self
    window.self是一個全局屬性,var一個self變量就會覆蓋window.self

打開新窗口

  • window.open("http://www.baidu.com",'_self');
    第一個參數(shù)為URL,第二個參數(shù)為windowName,第三個參數(shù)是window的一些屬性features
  • window.opener.location.reload()
    用在iframe頁面中,讓打開這個iframe頁面的頁面刷新。
  • 在頁面正中央打開一個指定寬高的窗口
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="test.js"></script>
</head>
<body>

<button id="btn">彈出窗口</button>
<script>
    var btn = document.querySelector('#btn');
    btn.addEventListener('click',function () {
        $.bom.openWindowAtCenter(1000,800,'http://baidu.com');
    })

</script>
</body>
</html>

test.js寫為:

window.$ = function () {}
$.bom = {
    openWindowAtCenter : function (width,height,url) {
        window.open(url,'_blank',`
            width = ${width}px,
            height = ${height}px,
            screenX = ${screen.width/2 - width/2}px,
            screenY = ${screen.height/2 - height/2}px,
`)
    }
}

修改查詢參數(shù)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容