View Full Version : Multiple child windows in Javascript Please Help!

01-22-2010, 11:52 AM

First off, I'm a noob have no idea about javascript teaching myself as I go along.

how do i have multiple child windows from my site? say i have a "music" page and within it i have a link to a child window and it opens fine, but I also have a "estore" page and within that page i have a link to another child window.

The problem I'm having is if the "music" child window is open and then I try to open the "estore" child window it opens up in the "music" child window or vice versa depending on what child window is open first. How can i get the estore child window to open in a different window to the music child window?

I hope this makes sense? I tried to describe it as best as I could with the limited knowledge I have!

01-22-2010, 12:32 PM
When you open a window using javascript, you are I would assume using the open() method or window.open() method (they're the same really) something like:

open('some.htm', 'someName', 'width=300, height=300');

Anyways, what you want is to have different names. These are also known as targets. If you have one name for the music one:

open('music.htm', 'musicwin', 'width=300, height=300');

and another for estore:

open('estore.htm', 'estorewin', 'width=300, height=300');

They will never open in each other's window. However, if someone opens two of the same windows, like two music windows, the second one will replace the first. If you want to avoid that, just open them all to _blank:

open('estore.htm', '_blank', 'width=300, height=300');

A _blank window will generally never replace another window.

Note: Some browsers may be able to override these settings.

01-22-2010, 01:00 PM
Hi John

Thanks for your help

so currently im using this code:

<a onclick="window.open (this.href, 'child', 'height=150,width=520'); return false" href="NEW_CHILD_WINDOW"><img class=" " style="margin-top: 0px; margin-bottom: 0px;" title="IMAGE_LINK"

If I change it to this:

<a onclick="window.open (this.href, 'MUSIC1', 'height=150,width=520'); return false" href="NEW_MUSIC_CHILD_WINDOW"><img class=" " style="margin-top: 0px; margin-bottom: 0px;" title="IMAGE_LINK"

will that work? I just need to change 'child' to a different name?

01-22-2010, 03:42 PM
Yes. I wonder about the href attribute of the link though. That should be the name of the folder or page that will populate the new window. Changing the href attribute from:




will probably result in the wrong page, or no page being displayed in the new window. All you should be changing is the name (also know as target) field of the the window.open() call from, as you say:

window.open (this.href, 'child', 'height=150,width=520')


window.open (this.href, 'MUSIC1', 'height=150,width=520')

01-22-2010, 03:58 PM
Cheers mate, I changed their names and it works perfectly! thanks for your help!