Results 1 to 5 of 5

Thread: How do I insert a target="_top" command

  1. #1
    Join Date
    Nov 2004
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How do I insert a target="_top" command

    in the "Rollover background-color button" script located here http://dynamicdrive.com/dynamicindex5/button3.htm ........ in the FORM section of the code, where would I put a [ target="top" ] command so that the page opens on a page by itself?


    <form onMouseover="change(event, 'yellow')" onMouseout="change(event, 'lime')">
    <input type="button" value="Yahoo" class="initial2" onClick="jumpto2('http://yahoo.com [would it go here?]')">
    </form>

    PS: i am calling the menu from an iframe and I want it to be able to break out of the iframe when the button is clicked.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Sure thing. Simply modify the orginal function jumpto2() inside the code of Step 1 to:

    Code:
    function jumpto2(url, breakout){
    if (typeof breakout!=undefined" && breakout=="break")
    window.parent.location=url
    if (buttontarget=="")
    window.location=url
    else if (buttontarget=="_new")
    window.open(url)
    else
    parent[buttontarget].location=url
    }
    Then inside your HTML, you can do things such as:

    Code:
    onClick="jumpto2('http://yahoo.com')" //NO targeting
    onClick="jumpto2('http://yahoo.com', 'break')" //break out of frame

  3. #3
    Join Date
    Nov 2004
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the quick response. It didn't work at first, but after taking a good look @ your modification, I noticed that a " was missing. Check it out here.

    function jumpto2(url, breakout){
    if (typeof breakout!="undefined" && breakout=="break")
    window.parent.location=url
    if (buttontarget=="")
    window.location=url
    else if (buttontarget=="_new")
    window.open(url)
    else
    parent[buttontarget].location=url
    }
    //-->
    Thanks again for your quick response and help
    Last edited by davidjovan; 12-15-2005 at 02:48 AM.

  4. #4
    Join Date
    Feb 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default correct and compatible

    isnt it more correct and more compatible to use this:

    self.frames[buttontarget].location.href=url

    in stead of the

    parent[buttontarget].location=url

    ( which gave me trouble with IE 6.0.2900.2180 ( sp2 ) )
    ?

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

    Default

    Yes, but they aren't interchangable.
    Which of the two you should use depends on where the script is being called from: parent... should be used if being called from within a frame at the same level as the target frame. self... should be used if called from the frameset page, or if using an iframe. You are partly right: parent[buttontarget] would be better expressed as parent.document.getElementById(buttontarget) or parent.document.getElementsByName(buttontarget)[0].
    Last edited by Twey; 02-03-2006 at 04:39 PM.
    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!

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
  •