Skip to content

Instantly share code, notes, and snippets.

@cgallagher
Created June 9, 2009 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgallagher/126391 to your computer and use it in GitHub Desktop.
Save cgallagher/126391 to your computer and use it in GitHub Desktop.
Snippet to prevent IE from storing iFrames loaded after page load as being an additional entry in the browser history in Internet Explorer. (Also kills the "click" noise in IE6) - ported to jQuery from YUI Version: http://www.julienlecomte.net/blog/2007/1
function setIFrameSrc(iframe, src) {
var el;
iframe = $(iframe)
if ($.browser.msie) {
// Create a new hidden iframe.
el = $(iframe).clone();
$(el).css("position", "absolute");
$(el).css("visibility", "hidden");
// keep the original iframe id unique!
$(el).attr("id", "");
// Listen for the onload event.
$(el).bind("load", function(){
// First, remove the event listener or the old iframe
// we intend to discard will not be freed...
$(this).unbind("load");
// Show the iframe.
$(this).css("position", "");
$(this).css("visibility", "");
// Replace the old iframe with the new one.
$(iframe).parent().replaceWith(this);
// Reset the iframe id.
$(this).attr("id", $(iframe.attr("id")));
});
// Set its src first...
$(el).attr("src", src);
// ...and then append it to the body of the document.
$("body").append(el);
}
else
{
iframe.src = src;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment