"Access denied" to iframe in IE
I'm trying to use hasnchange plugin writen by Ben Alman but have a problem when i using it in IE.
Code:
fake_onhashchange = (function(){
var self = {}, timeout_id, set_history, get_history, iframe, c, i;
c = $('#page');
i = $(document.createElement('iframe')).attr({'id': 'location-iframe', 'name': 'location-iframe', 'height': 50, 'src': '/iframe.html'});
c.append(i.load(function(){ iframe = this.contentWindow; }));
// Initialize. In IE 6/7, creates a hidden Iframe for history handling.
function init(){
// Most browsers don't need special methods here..
set_history = get_history = function(val){ return val; };
// But IE6/7 do!
if ( is_old_ie ) {
// Create hidden Iframe after the end of the body to prevent initial
// page load from scrolling unnecessarily.
// Get history by looking at the hidden Iframe's location.hash.
get_history = function() {
return get_fragment( iframe[ str_location ][ str_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[ str_location ].hash = '#' + hash; //In this place IE throws Access Denied error
}
};
// Set initial history.
set_history( get_fragment() );
}
};
iframe.html
:
<html>
<head>
<script type="text/javascript">
document.domain = 'some.net'; // as in parent window
</script>
</head>
<body>
</body>
</html>