FireFox and Local Links within Generated Content exhibits problems

Discussion in 'Javascript' started by Jim Davis, Sep 1, 2005.

  1. Jim Davis

    Jim Davis Guest

    The scenario: 1) Generate a popup window via script. 2) Populate it (again
    via script) with content that features local (hash) links.

    In IE 6.x this works - the links work as they should, moving the document to
    that document position. However in FireFox 1.x the links load the main page
    (the opener) in to the popup.

    Both browsers populate the location.href of the popup with the main page's
    href... but this only adversly affects FireFox (which seems to, in this
    scenario, reload the whole page on a local link). I tried manually
    populating the location.href but no joy.

    I've appended an example which demonstrates the problem. I've tried to
    shave it down as much as I could. Just save it to an HTML page and load it
    up in FireFox. Click the button then scroll down and click the link...
    instead of returning to the top of the page I get the opener page's HTML
    populated into the popup.

    Any thoughts on how to address this? I've Googled, but it may just be that
    I've been unable to hit on the right terms to uncover the answer.

    Thanks in advance for any direction,

    Jim Davis


    <html>
    <head>
    <title>Test Page</title>
    <script type="text/JavaScript">
    function CreateTestPopup() {
    // Create Window
    TestWindow =
    window.open("","TestWindow","scrollbars=yes,resizable=yes,width=500,height=400");
    var TW = TestWindow.document;
    // Write the HTML
    TW.write( "<html><head>",
    " <title>Test Window</title>",
    "</head><body>",
    "<a name='PageTop'>Page Top</a>",
    "<br><br><br><br><br><br><br><br><br><br><br>",
    "<a href='#PageTop'>Go To Page Top</a>",
    "</body></html>");
    };
    </script>
    </head>
    <body>
    <p>This is just a test page.</p>
    <p><input type="button" onclick="CreateTestPopup();" value="Launch
    Popup"></p>
    </body>
    </html>
    Jim Davis, Sep 1, 2005
    #1
    1. Advertising

  2. Jim Davis

    RobG Guest

    Jim Davis wrote:
    > The scenario: 1) Generate a popup window via script. 2) Populate it (again
    > via script) with content that features local (hash) links.
    >
    > In IE 6.x this works - the links work as they should, moving the document to
    > that document position. However in FireFox 1.x the links load the main page
    > (the opener) in to the popup.
    >
    > Both browsers populate the location.href of the popup with the main page's
    > href... but this only adversly affects FireFox (which seems to, in this
    > scenario, reload the whole page on a local link). I tried manually
    > populating the location.href but no joy.


    The problem is that because you don't supply a URL, the popup uses the
    URL of its parent. Clicking on the link links to the parent page - see
    below.

    [...]
    >
    > <html>
    > <head>
    > <title>Test Page</title>
    > <script type="text/JavaScript">
    > function CreateTestPopup() {
    > // Create Window
    > TestWindow =
    > window.open("","TestWindow","scrollbars=yes,resizable=yes,width=500,height=400");
    > var TW = TestWindow.document;
    > // Write the HTML
    > TW.write( "<html><head>",
    > " <title>Test Window</title>",
    > "</head><body>",
    > "<a name='PageTop'>Page Top</a>",


    "<br><div onclick='alert(window.location.href)'>",
    "Show href</div>",

    > "<br><br><br><br><br><br><br><br><br><br><br>",
    > "<a href='#PageTop'>Go To Page Top</a>",
    > "</body></html>");
    > };
    > </script>
    > </head>
    > <body>
    > <p>This is just a test page.</p>
    > <p><input type="button" onclick="CreateTestPopup();" value="Launch
    > Popup"></p>
    > </body>
    > </html>


    Click on the text 'Show href' in the popup to see what I mean.

    You could try linking to a real document and replace the content of the
    HTML element. That will allow you to set a doctype etc and have a valid
    document to boot.



    --
    Rob
    RobG, Sep 1, 2005
    #2
    1. Advertising

  3. Jim Davis

    Jim Davis Guest

    "RobG" <> wrote in message
    news:LAuRe.343$...
    > Jim Davis wrote:

    <snip>

    > The problem is that because you don't supply a URL, the popup uses the URL
    > of its parent. Clicking on the link links to the parent page - see below.


    Yes... I agree that this is probably the cause... but how to get around it?

    The behavior still strikes me as damn peculiar. I mean if FireFox sets the
    href as the main page, fine (so does IE) - but internally it must lose this
    someplace because it reloads the entire page when you go to an internal
    link. On any other page with internal links it doesn't seem to reload the
    page - it just scrolls to the target.

    For it to do what it's doing it has to be comparing what it's displaying as
    the href with something else, finding them different and reloading the page
    using the "new" href.

    > Click on the text 'Show href' in the popup to see what I mean.


    Oh - I already knew that: I actually said so in my original message. ;^)

    > You could try linking to a real document and replace the content of the
    > HTML element. That will allow you to set a doctype etc and have a valid
    > document to boot.


    I'm sure that would solve it.

    Unfortunately in this case I can't link a "real" document - this code is
    part of a public debugging library: it may be used with Internet Access,
    without Internet access, locally via a server, etc. The libraries may be
    called from an external file or embedded in the main page.

    As for the doctype - there's no reason I can't set it here: I just stripped
    the code to the bone for the example (the code displays the same behavior
    doctype or no).

    Thanks for the thoughts,

    Jim Davis
    Jim Davis, Sep 1, 2005
    #3
  4. *** Jim Davis wrote/escribió (Wed, 31 Aug 2005 22:11:00 -0400):
    > The scenario: 1) Generate a popup window via script. 2) Populate it (again
    > via script) with content that features local (hash) links.
    >
    > In IE 6.x this works - the links work as they should, moving the document to
    > that document position. However in FireFox 1.x the links load the main page
    > (the opener) in to the popup.


    If you add document.write(this.location.href) to the child window you'll
    see that its URL remains the same as its parent's (that's the same in both
    browsers). So IE's behaviour is not really consistent.

    I suggest you use the focus() method to browse child page.


    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- http://bits.demogracia.com - Mi sitio sobre programación web
    -- Don't e-mail me your questions, post them to the group
    --
    Alvaro G Vicario, Sep 1, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steffen Netz
    Replies:
    0
    Views:
    637
    Steffen Netz
    May 3, 2004
  2. hazz
    Replies:
    6
    Views:
    49,541
    SkyUCHC
    Jun 9, 2010
  3. Dan D.
    Replies:
    0
    Views:
    383
    Dan D.
    Sep 12, 2006
  4. jackogreen
    Replies:
    1
    Views:
    159
    Aaron [SQL Server MVP]
    Aug 25, 2004
  5. millhauser
    Replies:
    7
    Views:
    121
    Thomas 'PointedEars' Lahn
    Apr 2, 2005
Loading...

Share This Page