window.open,用于打开一个新的页面

2017-06-21  本文已影响194人  WangYatao

****效果图****
有时候我们在打开一个网页的时候会在打开网页的同时在浏览器的左上角弹出一个广告框,这里就可以使用window.open来实现


Paste_Image.png

****语法:window.open([URL], [窗口名称], [参数字符串])
window.open有三个属性,第一个是打开的网页地址,第二个打开方式,第三个设置打开的网页样式****
****打开方式有
_blank:在新窗口显示目标网页
_self:在当前窗口显示目标网页
_top:框架网页中在上部窗口中显示目标网页****
****打开样式:****


Paste_Image.png
****代码****
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .con{width:300px;height: 200px;margin: 0 auto;}
        </style>
</head>
<body>
<div class="con"><h1>Hello</h1></div>
</body>
<script>
window.open('http://www.baidu.com','_blank','top=300,left=300,width=500,height=400')
</script>
</html>
上一篇 下一篇

猜你喜欢

热点阅读