Get rid of the IE iframe “click”
Written by on November 12th, 2007 in Ajax News.
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)
Source: Ajaxian
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/183544425/get-rid-of-the-ie-iframe-click