Results 1 to 9 of 9

Thread: target in javascript

  1. #1
    Join Date
    Dec 2005
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default target in javascript

    I need to change this:
    <A HREF="page.html" target="name of frame">do it</A>
    to something like this:
    onload="window.location='page.html';"

    how do I do the target in js?

    thanks

  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

    It can depend upon what page you are putting this code on but, in many cases, this will do the trick:

    HTML Code:
    <body onload="parent.name of frame.location='page.html'">
    or as part of a script:

    Code:
    onload=function(){
    parent.name of frame.location='page.html';
    }
    - John
    ________________________

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

  3. #3
    Join Date
    Dec 2005
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    What about this:

    <BUTTON onclick="window.location=search.cat.options[search.cat.selectedIndex].value + search.user.value;">Search</BUTTON>

    What would I do if I wanted the target to be _blank?
    Last edited by toe_head2001; 01-09-2006 at 03:54 AM.

  4. #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

    That's a special case, simulating target="_blank". To do that in javascript one needs to open a new window, a pop up. Generally this is fine for a click event but, some aggressive pop up blockers will even stop that. Be that as it may, here is the code:

    Code:
    <input type="button" onclick="window.open(search.cat.options[search.cat.selectedindex].value + search.user.value);" value="Search">
    - John
    ________________________

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

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Quote Originally Posted by John
    Generally this is fine for a click event but, some aggressive pop up blockers will even stop that.
    They shouldn't. If a popup blocker blocks window.open() calls contained within an onclick event, said popup blocker is broken.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    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

    Quote Originally Posted by Twey
    They shouldn't. If a popup blocker blocks window.open() calls contained within an onclick event, said popup blocker is broken.
    Not broken, no. Agressive. They (some pop up blockers) can be set to specifically be that aggressive.
    - John
    ________________________

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

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Disabling useful and often necessary functionality initiated (almost certainly knowingly) by the user is, to my way of thinking, destructive behaviour.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I agree with John, though it's rather more fact that than opinion. Both built-in (IE and Opera) and third-party (especially proxy) blockers allow the user to prevent the appearance of all pop-ups.

    Disabling useful and often necessary functionality initiated (almost certainly knowingly) by the user is, to my way of thinking, destructive behaviour.
    How so, if the user disabled all pop-ups?

    Mike

  9. #9
    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

    Thanks, Mike. There is always this (and similar, some even more egregious) situation:

    HTML Code:
    <a href="http://www.google.com" onclick="window.open('obnoxious_ad.htm');return true;">Google</a>
    I can see why some would, and have been tempted myself at times to, disable all pop ups because of designers who take advantage of this loophole.
    - John
    ________________________

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

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
  •