确保在新窗口中打开的 Javascript 方法(不是选项卡)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13636548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript Method to Ensure Open in New Window (not Tab)
提问by Jesse Q
Bear with me as this might seem similar to ( JavaScript open in a new window, not tab), but the method by which the link is executed is different. I am opening a "Sales Script" application via a third party application when a soft phone is answered. If the sales rep already has a browser window open (and they always do), a new tab is opened within the existing window and it isn't always readily noticeable. They are requesting that I always have my application pop a new window, but as near as I can tell the only way to do this is via the browser's preferences. Is there by any chance some javascript I am not aware of that will "undock" a tab? I suspect the answer is no, but had to ask.
请耐心等待,因为这可能看起来类似于(在新窗口中打开 JavaScript,而不是选项卡),但执行链接的方法不同。当接听软电话时,我正在通过第三方应用程序打开“销售脚本”应用程序。如果销售代表已经打开了一个浏览器窗口(他们总是这样做),则会在现有窗口中打开一个新选项卡,并且并不总是很容易注意到。他们要求我总是让我的应用程序弹出一个新窗口,但据我所知,唯一的方法是通过浏览器的首选项。是否有一些我不知道的 javascript 会“取消停靠”选项卡?我怀疑答案是否定的,但不得不问。
Thanks for your time!
谢谢你的时间!
[EDIT] I thought maybe this was out of scope of the question initially, but I think it could shed light on what I am trying to do: A 3rd party app (iSymphony) runs on the local machine and listens to events on our call controller. When the rep answers, it fires a URL, which is opened in the system's default browser. I don't really have any control over how it's opened, which is why I was hoping for a javascript solution to ensure I was in a new window.
[编辑] 我认为这最初可能超出了问题的范围,但我认为它可以阐明我想要做的事情:第 3 方应用程序 (iSymphony) 在本地机器上运行并在我们通话时监听事件控制器。当代表回答时,它会触发一个 URL,该 URL 在系统的默认浏览器中打开。我真的无法控制它的打开方式,这就是为什么我希望有一个 javascript 解决方案来确保我在一个新窗口中。
回答by Kelvin
If you specify the width and height when you call window.open
, most browsers will open the link in a new window rather than a tab.
如果在调用时指定宽度和高度window.open
,大多数浏览器将在新窗口而不是选项卡中打开链接。
window.open(url, '_blank', 'width=300,height=200');
Fiddle: http://jsfiddle.net/kelervin/Pf8Rw/
小提琴:http: //jsfiddle.net/kelervin/Pf8Rw/
See this questionfor discussion and more detail.
有关讨论和更多详细信息,请参阅此问题。
If the intent is to get the user's attention, you could consider adding desktop notifications (assuming a browser like Chrome that supports them is an option).
如果目的是引起用户的注意,您可以考虑添加桌面通知(假设支持它们的 Chrome 浏览器是一种选择)。
See this answerfor an example, it might be just what you're looking for.
请参阅此答案以获取示例,它可能正是您要查找的内容。