jhsachs Posted August 9, 2011 Share Posted August 9, 2011 Here's a small JavaScript puzzle, probably trivial to those more familiar with JavaScript than I am. My PHP script wants to open a new browser tab, display a page in it, and shift the focus to it. If the tab is already open, it wants to shift the focus to the tab without opening a new one. I found that window.open does what I want, as far as opening the tab goes, out of the box. Thus I can open the tab if and only if it doesn't already exist like this: window.open('www.somewhere.com/newtab_page.html', '_newtab'); window.open returns a reference to the tab whether it already exists or not, right? So I should be able to open the tab if it doesn't exist and make it the current tab like this: var newtab = window.open('www.somewhere.com/newtab_page.html', '_newtab'); newtab.focus(); But it works only if the tab does not already exist. If the tab exists, it does nothing. Why is that, and how can I fix it? Quote Link to comment https://forums.phpfreaks.com/topic/244279-shifting-focus-to-a-browser-tab/ Share on other sites More sharing options...
jhsachs Posted August 9, 2011 Author Share Posted August 9, 2011 Just in case this is a platform-dependent issue, I'm using Firefox 4.0 under Windows XP. Quote Link to comment https://forums.phpfreaks.com/topic/244279-shifting-focus-to-a-browser-tab/#findComment-1254666 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.