Results 1 to 5 of 5

Thread: Multiple child windows in Javascript Please Help!

  1. #1
    Join Date
    Jan 2010
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Multiple child windows in Javascript Please Help!

    Hello

    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!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    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:

    Code:
    open('music.htm', 'musicwin', 'width=300, height=300');
    and another for estore:

    Code:
    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:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    drewstain (01-22-2010)

  4. #3
    Join Date
    Jan 2010
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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?

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    href="NEW_CHILD_WINDOW"
    to:

    Code:
    href="NEW_MUSIC_CHILD_WINDOW"
    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:

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

    Code:
    window.open (this.href, 'MUSIC1', 'height=150,width=520')
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. The Following User Says Thank You to jscheuer1 For This Useful Post:

    drewstain (01-22-2010)

  7. #5
    Join Date
    Jan 2010
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Cheers mate, I changed their names and it works perfectly! thanks for your help!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •