views:

14

answers:

1

Hello, i have a link on my web page; when i click it i open a new window and show content in that window.

I would like to be able, in a second time, to click again in that link and, instead of opening a new browser window/tab, to get the previous instance and put content on it.

Is it possible in some way?

Thanks in advance, greetings c.

+2  A: 

In HTML you do this by specifying a named target:

<a href="page2.html" target="myotherwindow">Link 2</a>
<a href="page3.html" target="myotherwindow">Link 3</a>
<a href="page4.html" target="myotherwindow">Link 4</a>

All will open in the same window.

Note: If the user has their preferences set to open new windows in tabs, these will all reference the same tab (vs. window)

scunliffe
Thanks, i didn't know it ! But when i click the second time (in Firefox) content is loaded in the new tab but it remains hidden, is it normal?
Cris
Correct, it changes the content but does not assign focus. If you want to do that, you'll need to use the JavaScript `window.open(url,name,features);` method. When you assign a name, you can then later give it focus... e.g. create the popup `window.open('page3.html', 'myotherwindow','statusbar=yes');` load new content... `myotherwindow.document.location.href = 'page4.hmtl';` then (re)set the focus `myotherwindow.focus();`
scunliffe
Great, my friend, you're the man !!I've made my_win=window.open('page.html','mywindow');if(my_win!=null) my_win.focus();Thank you very much!!
Cris