Why does this JavaScript cause a "Permission Denied" error in IE
The following code throws a Permission Denied
error in IE, citing jQuery (1.6.2) line 6244 Char:2:
function addAgreement() {
var url = window.location.toString();
var pieces = url.split('/');
var site_url = url.replace(pieces[pieces.length -1], '');
$('.login').append('<div id="dialog"></div>');
$('#dialog').load(site_url + '?page_id=443');
}
$('#dialog').dialog({
width: 800,
position: 'top',
modal: true,
buttons: {
"Agree": function() {
agreed = true;
var val = $('#registerform').attr('action') + '&agreed=1';
$('#registerform').attr('action', val);
$(this).dialog("close");
$('#registerform').trigger('submit');
},
"Disagree": function() {
agreed = false;
$(this).dialog("close");
}
}
});
It works in Firefox — is this som开发者_开发技巧ething to do with same origin policy? jQuery is being served by Google CDN.
UPDATE
The content being loaded is a WordPress page which also contains includes for cufon-yui.js
(served locally). I have tried serving jQuery locally too (i.e not from the Google CDN) and this made no difference.
UPDATE 2 Removing the following script tags from the loaded page stops the error from appearing.
<script type='text/javascript' src='<?php echo bloginfo('template_url') ?>/inc/js/cufon-yui.js'></script>
<script type='text/javascript' src='<?php echo bloginfo('template_url') ?>/inc/js/path/to/font.js'></script>
<script type='text/javascript'>
Cufon.replace('#page')('.title');
</script>
For AJAX requests, www. is seen as a sub-domain and breaks the same-origin policy for the xmlhttprequestobject. Make sure the domain in your AJAX request matches the domain of the page and your javascript file.
精彩评论