Firefox reloading parent page in iframe when clicking named anchor
Posted
by masty
on Stack Overflow
See other posts from Stack Overflow
or by masty
Published on 2010-04-11T23:15:52Z
Indexed on
2010/04/11
23:23 UTC
Read the original article
Hit count: 408
My site has an iframe which is dynamically populated with html content. The html often contains named anchors, which work fine in IE/Chrome but in Firefox it reopens the entire page within the iframe.
Here's an example: load the page in firefox, scroll to the bottom of the iframe, click the "back to top" link, and you will see what I am talking about.
<html><head></head><body onload="setFrameContent();"><script>
var htmlBody = '<html> <head></head> <body>' +
'<a name="top"><h1>top</h1></a>' +
'<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>' +
'<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>' +
'<a href="#top">back to top</a></body> </html> ';
function setFrameContent(){
if (frames.length > 0) {
var d = frames[0].document;
d.open();
d.write(htmlBody);
d.close();
}
}
</script>
<h1>Here's an iframe:</h1>
<iframe id="htmlIframe" style="height: 400px; width: 100%"><p>Your browser does not support iframes.</p></iframe>
</body></html>
Any ideas?
© Stack Overflow or respective owner