问题描述
我有一个应该在新标签中打开的链接,但是如果该标签已经打开,只需切换到该链接即可。
我试过用javascript,wnd = window.open()和wnd.focus(),它可以在Chrome 19中运行,但不能在FF 13或IE 9中运行。
这里是代码I'已经写成:
I have a link which should open in a new tab, but if the tab is already open, just switch to it. I've tried with javascript, wnd = window.open() and than wnd.focus(), that works in Chrome 19, but not in FF 13 or IE 9. Here's the code I've written :
<script type="text/javascript">
var loadingTableWnd;
function openOrSwitchToWindow(url){
if(loadingTableWnd == undefined)
loadingTableWnd = window.open(url,'myFrame');
else
loadingTableWnd.focus();
}
</script>
<a href='javascript:openOrSwitchToWindow("/");' >Loading Table</a>
任何想法如何从每个浏览器打开或切换?
Any idea how can I open or switch to from every browser?
编辑:我需要在新标签中打开链接,而不是独立窗口。
EDIT: I need to open the link in a new tab, not a stand-alone window.
推荐答案
不同的浏览器对window.open()和focus()的行为不同。
此代码 window.open('www.sample.com','mywindow')。focus()
Different browsers behave differently for window.open() and focus().For this code window.open('www.sample.com','mywindow').focus()
- Chrome 20 不管是否调用focus(),都会打开一个新选项卡,并专注于后续的open()调用。 $ b
- Firefox 13 打开一个新选项卡,重点放在第一个open(),不关注随后的open()调用/忽略focus()。
- IE 8 打开一个新窗口,授予焦点()。 Safari 5 打开一个新窗口, open()调用,而不管是否调用了focus()。
- Chrome 20 opens a new tab, and focuses on subsequent open() calls regardless if focus() is called or not.
- Firefox 13 opens a new tab, focuses on first open(), does not focus on subsequent open() calls/disregards focus().
- IE 8 opens a new window, honors focus().
- Safari 5 opens a new window, and focuses on subsequent open() calls regardless if focus() is called or not.
小提琴测试:
这篇关于如果已打开,请在新窗口中打开链接或关注它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!