window.close()是用来关闭窗口的,而且ie和firefox都是支持的。

为了实现用户对浏览器的绝对控制,ie中用close关闭非open打开的窗口时回弹出一个对话框询问用户,怎么去掉这个框呢,请看下面的代码。



function winClose(){ window.top.opener = null; window.close(); }



在window.close之前加上window.top.opener = null就可以了


 




有人说firefox不支持close,其实这是错误的,之所以window.close在firefox不能使用,是因为firefox默认不能关闭用户打开的网页,可以这样设置firefox。



打开firefox,在地址栏输入about:config


找到dom.allow_scripts_to_close_windows这项并改为true。

需要说的是在firefox中没有弹出对话框的麻烦。



<script>

function a(){

window.open('','_parent','');

window.opener = window;

window.close();

}


</script>

再运行这个就能在ff下关闭了。



看到这些,如果让客户去设置的话,等于没有做这个功能,所以说结果不是很满意。




利用打开一个新窗口,然后关闭这个页面就可以实现关闭当前页面。




index.html

<a href="c.html" target="_blank">ddddddddd</a>




c.html

<a href="javascript:window.open('','_parent','');window.close();">Close Window</a>

This entry was posted on 21:52 and is filed under . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

0 评论: