The dilemma that I'm dealing with is that in the jquery-bbq code, because IE6 and IE7 do not support hashchange
, they load pages twice in order to have a history state.
This has a negative effect because code runs twice on both server-side and client-side. The method used to create the iframe is this:
if ( is_old_ie ) {
// Create hidden IFRAME at the end of the body.
iframe = $('<iframe src="javascript:0"/>').hide().appendTo( 'body' )[0].contentWindow;
// Get history by looking at the hidden IFRAME's location.hash.
get_history = function() {
return get_fragment( iframe.document.location.href );
};
// Set a new history item by opening and then closing the IFRAME
// document, *then* setting its location.hash.
set_history = function( hash, history_hash ) {
if ( hash !== history_hash ) {
var doc = iframe.document;
doc.open().close();
doc.location.hash = '#' + hash;
}
};
// Set initial history.
set_history( get_fragment() );
}
A blank iframe with a src of javascript:0
is created. The document.open
method is called, and it seems like it grabs the location.href
of the parent window as the default for the page that opens with .open
.
I basically have to modify the code so that it doesn't open the same url twice, so I'm looking to override the default and specify a param such as ?iframe=true.
Example:
http://example.com/views/step-2?one=two
In IE, the page above gets loaded and then gets loaded again in an iframe. The server-side code executes twice, but I don't want that to happen.
I want to append &iframe=1
to the URI so I can prevent my server-side code from running if the iframe
param is specified.
The two most obvious things are:
document.open.close
, use iframe.location.href
and set it to the href manually.If anyone has had experience with iframe hacking, I'd greatly appreciate some tips.
EDIT: Another workaround I thought of would be loading a page through iframe/ajax that sets a session var before the iframe does the document.open
, which creates a session variable of 'iframeloading' which is equal to 1, and set a load event handler on iframe load to set it back to 0, and adjust my server-side code to not execute if the session var is set to 1. Something like:
$('<iframe src="/iframe-loading.php"/>').hide().appendTo('body');
document.open().close()
$( document.defaultView ).load(function() {
$('<iframe src="iframe-doneloading.php/>').hide().appendTo('body');
});
About "Is there a standard way of defining the href that opens in a document.open call?"
No, there is not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With