用于关闭其他标签或浏览器的脚本 [英] Script to close other tabs or browser

查看:440
本文介绍了用于关闭其他标签或浏览器的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我为销售开发的MVC应用程序中,我有一个按钮,用于打开一个不允许在新标签页中打开iframe的网页。因此,当销售代理使用此按钮时,他们通常不会关闭应用程序打开的选项卡,并且在一天结束时,有20-30个打开的选项卡。所以,我想知道是否有一个脚本我可以添加到一个可以关闭的新按钮:

In my MVC application being developed for sales, I have a button which opens a web page which doesn't allow iframe to open in a new tab. So, when the sales agent use this button, they often don't close the tabs opened by the application and in the end of the day, there is 20-30 of open tabs. So, I was wondering if there is a script which I can add to a new button which could close:


  1. 完整的浏览器全部其中的标签可以重新开始或

  2. 关闭所有其他标签而不影响当前标签。

在视图中,我有

<input type="submit" onclick="return OpenInNewTab('http://test.com');" name="command" value="nonIframe" background-image:url(../images/URL/Test.png);" class="submit" />



Javascript



Javascript

//Function OpenInNewTab
function OpenInNewTab(url) {
    var win = window.open(url, '_blank');
    win.focus();
    return false;
}

我正在玩这个脚本,但它只关闭当前标签。我希望当前标签打开并关闭所有标签其他标签或关闭整个浏览器本身。

I was playing with this script, but it only closes the current tab. I want the current tab to be open and close all other tabs or close the entire browser itself.

<script language="JavaScript">
    function closeIt() {
        close();
    }
</script>



HTML



HTML

<center>
    <form>
        <input type=button value="Close Window" onClick="closeIt()">
    </form>
</center>

任何建议都是非常感谢。
谢谢

Any suggestions would be really appreciated. Thank You

推荐答案

如果你有句柄,你只能关闭窗户。这意味着您的页面必须是打开它们的页面(或者您以某种方式传递了句柄)。

You can only close windows if you have their handle. That means your page needs to have been the one that opened them (or you somehow passed the handle around).

示例:

var winGoogle = window.open('http://google.com', '_blank');
var winBing = window.open('http://bing.com', '_blank');
var winYahoo = window.open('http://yahoo.com', '_blank');

//close the windows
winGoogle.close();
winBing.close();
winYahoo.close();

您可以将这些新窗口存储在一个数组中,并在需要关闭时迭代句柄他们。

You could store these new windows in an array, and iterate over the handles when it is time to close them.

var windows = [];
//each time you open a new window, simply add it like this:
windows.push(window.open('http://google.com', '_blank'));

//then you can iterate over them and close them all like this:
for(var i = 0; i < windows.length; i++){
    windows[i].close()
}

这篇关于用于关闭其他标签或浏览器的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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