前端相关

BOM

2017-08-20  本文已影响0人  DeeJay_Y

BOM

Browser Object Model

打开新窗口

<!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,
`)
    }
}

修改查询参数

上一篇 下一篇

猜你喜欢

热点阅读