Opening 2 individual pages using the same new window?

Hi all,

Basically I have created 3 pages - index.html, page1.html + page2.html

I have 2 links in index.html that link off to page1.html + page2.html

My question is, can I use javascript in such a way that if I click link 1 then page1.html opens in a new window but if I then click link 2 then page2.html appears in the window that currently has page1.html?

If anyone can suggest what can be done would be great, here is a link to my page: XHTML5 Skel

Thanks for your help!

Kyle

Simply specify a name for the window in the second parameter of the window.open() and they will all use the one window that has that name and only create a new window if a window with that name doesn’t already exist (avoid using a name that starts with an underscore as some of those names have special meanings such as _blank meaning to always open a new window).

Hi Felgall,

Thanks for the reply, Does this mean I will have to add the code directly into the anchor tags or can this be seperate from the html?

Kyle

No, for F’s sake no! Don’t faff about with the HTML code.

I see that you are already loading jQuery, so you can easily use that to achieve your needs.


$('#container a').click(function (evt) {
    window.open(this, 'childWindow', 'width=600,height=400');
    evt.preventDefault();
});

The purpose of specifying a width and height, is to help encourage web browsers to not open the window as a new tab, but as a separate window instead.

The preventDefault part prevents the parent window from performing its default action of opening up the new page in the parent window.