是否可以使用javascript关闭浏览器窗口? [英] Is it possible to close a browser window using javascript?

查看:119
本文介绍了是否可以使用javascript关闭浏览器窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用java脚本关闭浏览器窗口。

I need to close the browser window using the java script.

我尝试过使用window.close但它无效。

I have tried using window.close but it is not working.

我也搜索并检查了任何类似帖子的堆栈溢出。我也经历过以下链接,但徒劳无功。

I have also googled and checked stack overflow for any similar posts. I have also gone through following link but in vain.

是否可以从JavaScript关闭浏览器窗口?

我要做的是加载一个页面和页面加载调用一个java脚本方法,它执行window.close

What I am trying to do is load a page and on load of the page call a java script method which does window.close

下面是代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
function closeBrowser(){
    window.close();
}
</script>
</head>
 <body onload="closeBrowser();">
 </body>
</html>

虽然它在IE8中正常工作。它不在火狐中工作。

It is properly working in IE8 though. Its not working in the fire fox.

即使在IE中,它也会在实际关闭浏览器之前提供警报提示。我们可以避免在IE中发出警报吗?

And even in IE it gives the alert prompt before actually closing the browser. Can we avoid the alert in IE?

为什么它在火狐中不起作用?

Why it does not work in fire fox?

推荐答案

它不在火狐中工作的原因是由于火狐的某些设置。

The reason it was not working in fire fox was due to some settings in the fire fox.

请设置你的firefox浏览器:

Please set your firefox browser:

1.输入about:config到你的firefox地址栏和输入;

1.input "about:config " to your firefox address bar and enter;

2.确保你的dom.allow_scripts_to_close_windows为真

2.make sure your "dom.allow_scripts_to_close_windows" is true

window.close现在正在工作在火狐中也是如此。

window.close is now working in fire fox too.

这篇关于是否可以使用javascript关闭浏览器窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆