为什么此JavaScript会导致“权限被拒绝"? IE中的错误 [英] Why does this JavaScript cause a "Permission Denied" error in IE
问题描述
下面的代码在IE中引发Permission Denied
错误,引用jQuery(1.6.2)第6244行Char:2:
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");
}
}
});
它在Firefox中有效-这与原产地政策有关吗? jQuery由Google CDN提供服务.
It works in Firefox — is this something to do with same origin policy? jQuery is being served by Google CDN.
更新
正在加载的内容是一个WordPress页面,其中还包含cufon-yui.js
的包含内容(本地提供).我也尝试过在本地提供jQuery(即不是从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.
更新2 从加载的页面中删除以下脚本标记可阻止该错误出现.
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>
推荐答案
对于AJAX请求,请访问www.被视为子域,并且违反了xmlhttprequestobject的同源策略.确保您的AJAX请求中的域与页面域和javascript文件相匹配.
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.
这篇关于为什么此JavaScript会导致“权限被拒绝"? IE中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!