弹出窗口的js

来源:互联网 发布:外围服务 知乎 编辑:程序博客网 时间:2024/03/29 12:30

本网页JavaScript代码

本网页JS,只有一个函数,它负责打开一个300*300的网页。

<script type="text/javascript">function test(){window.open('04_popup_test.html','popup','width=300,height=300')}</script>

HTML代码

<form action="#"><button onclick="test(); return false;" value="test" >点击测试</button></form> 

效果

弹出网页JavaScript代码

弹出网页JS,首先,可以使用window.opener来引用打开父网页的window,再用location输出它的地址。最后有一个函数,可以利用它改变父网页的背景颜色。我们还可以做很多事情,这只是一个JavaScript窗口间通信的小例子。

<script type="text/javascript">farther = window.opener;document.write(farther.location);function changeFarther(){farther.document.getElementById('content').style.backgroundColor = "yellow";}</script>

HTML代码

<button onclick="changeFarther(); return false;">设置背景颜色</button>    

原创粉丝点击