FireFox and Local Links within Generated Content exhibits problems

J

Jim Davis

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>
 
R

RobG

Jim said:
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 said:
"<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.
 
J

Jim Davis

RobG said:
Jim Davis wrote:
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
 
A

Alvaro G Vicario

*** 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top