Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  71] [ 2]  / answers: 1 / hits: 91473  / 12 Years ago, mon, june 11, 2012, 12:00:00

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.


More From » html

 Answers
42

Different browsers behave differently for window.open() and focus().
For this code window.open('www.sample.com','mywindow').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.



Fiddle to test with: http://jsfiddle.net/jaraics/pEG3j/


[#84990] Saturday, June 9, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
blaynetheoi

Total Points: 146
Total Questions: 116
Total Answers: 103

Location: India
Member since Thu, Apr 8, 2021
3 Years ago
;