Get rid of the IE iframe “click”
I am sure you have run into this before. You are on a site, interacting with a single page app, and then you hit the back button and IE clicks at you. The navigation “click” happens with iframes, and be a nuisance if you are trying to use iframes in a non-navigational way.
Julien Lecomte has a work around to by pass it by replacing DOM nodes with new iframes and such:
-
-
function setIFrameSrc(iframe, src) {
-
var el;
-
iframe = YAHOO.util.Dom.get(iframe);
-
if (YAHOO.env.ua.ie) {
-
// Create a new hidden iframe.
-
el = iframe.cloneNode(true);
-
el.style.position = “absolute”;
-
el.style.visibility = “hidden”;
-
// keep the original iframe id unique!
-
el.id = “”;
-
// Listen for the onload event.
-
YAHOO.util.Event.addListener(el, “load”, function () {
-
// First, remove the event listener or the old iframe
-
// we intend to discard will not be freed…
-
YAHOO.util.Event.removeListener(this, “load”, arguments.callee);
-
// Show the iframe.
-
this.style.position = “”;
-
this.style.visibility = “”;
-
// Replace the old iframe with the new one.
-
iframe.parentNode.replaceChild(this, iframe);
-
// Reset the iframe id.
-
this.id = iframe.id;
-
});
-
// Set its src first…
-
el.src = src;
-
// …and then append it to the body of the document.
-
document.body.appendChild(el);
-
} else {
-
iframe.src = src;
-
}
-
}
-
I loved Julien’s note:
This technique is used by the new Yahoo! Mail (which used to sound like an automatic rifle…:0)
Read more on the source site
No comments yet.
feel free to leave a comment
Comment Guidelines: Basic XHTML is allowed (a href, strong, em, code). All line breaks and paragraphs are automatically generated. Off-topic or inappropriate comments will be edited or deleted. Email addresses will never be published. Keep it PG-13 people!
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
All fields marked with " * " are required.

