简体   繁体   English

在IE中防止“SCRIPT5:访问被拒绝”错误

[英]Preventing “SCRIPT5: Access is denied” error in IE

Scenario: Page A on A.com that has an IFrame containing Page B on B.com. 场景:A.com上的页面A在B.com上有一个包含页面B的IFrame。 Page B uses jQuery 1.10.1 and does not need to communicate with Page A. 网页B使用jQuery的1.10.1并且不需要与页面A.沟通

Regardless of this fact, in IE9 and IE10, jQuery generates a "SCRIPT5: Access is denied." 无论如何,在IE9和IE10中,jQuery会生成“SCRIPT5:访问被拒绝”。 error and seemingly refuses to execute any jQuery at all. 错误,似乎拒绝执行任何jQuery。 I have no need of cross-domain communication, AJAX requests, etc., but I do need jQuery to load and execute without errors in Page B. 我不需要跨域通信,AJAX请求等,但我确实需要在页面B中加载和执行jQuery而不会出错。

Is there a way to prevent this error from appearing (and inhibiting code execution) in IE9 and IE10? 有没有办法防止IE9和IE10中出现此错误(并禁止执行代码)? (FYI, other browsers similarly generate "access denied" errors, but they do not hinder code execution) (仅供参考,其他浏览器类似地生成“拒绝访问”错误,但它们不会妨碍代码执行)


UPDATE: 更新:

jsFiddle: http://jsfiddle.net/86q5k/4/ jsFiddle: http//jsfiddle.net/86q5k/4/

The contents of the host page are (from the jsFiddle): 主页的内容是(来自jsFiddle):

<iframe src="http://endorkins.com/test-iframe.html"></iframe>

The contents of the iFramed page are: iFramed页面的内容是:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            console.log('Hello!  Congratulations.  Your browser is neat, and doesn\'t sniff glue! (http://bit.ly/12QTvTT)');
        });
    </script>
</head>
    <body>
    </body>
</html>

Result in Chrome (Notice the message in the console): Chrome中的结果(请注意控制台中的消息): 在此输入图像描述

Result in IE 9.0.8112 (Notice the omission of the message in the console): IE 9.0.8112中的结果(注意在控制台中省略了消息):

在此输入图像描述

I found a workaround. 我找到了一个解决方法。 This appears to be a bug ("feature"?) in jQuery 1.10.1. 这似乎是jQuery 1.10.1中的一个错误(“功能”?)。 Using jQuery 1.10.0, the error no longer occurs: 使用jQuery 1.10.0,不再出现错误:

http://jsfiddle.net/86q5k/5/ http://jsfiddle.net/86q5k/5/

<iframe src="http://endorkins.com/test-iframe-1.10.0.html"></iframe>

Strange. 奇怪。 Very strange. 很奇怪。 If anyone knows the reason why this is happening in 1.10.1, and how to fix it, I (and jQuery minions around the globe) would certainly be very interested to know! 如果有人知道为什么会在1.10.1中发生这种情况,以及如何解决它,我(以及全球各地的jQuery小伙伴)肯定会非常有兴趣知道! :) :)


UPDATE: Looks like this is a legit jQuery 1.10.1 bug: http://bugs.jquery.com/ticket/13980 更新:看起来这是一个合法的jQuery 1.10.1错误: http//bugs.jquery.com/ticket/13980


UPDATE: According to @emanuele-greco, this is fixed in 1.10.2 and up. 更新:根据@ emanuele-greco,这在1.10.2及更高版本中得到修复。 So, upgrading your version of jQuery will likely fix the problem. 因此,升级您的jQuery版本可能会解决问题。

Ok I Found the same problem and fixed it with the weirdest and most horrible solution ever. 好的我发现了同样的问题并用最奇怪和最可怕的解决方案修复了它。

I'm trying to use an image to popup the file upload dialog, then do an automatic form submit on the change event. 我正在尝试使用图像弹出文件上传对话框,然后对更改事件执行自动表单提交。 I had resigned my self that in IE the users were going to have to click an image to do the post. 我已经辞职了,在IE中用户将不得不点击图片来发布帖子。 I placed the image on the form (like i have in several places on the site. This to generated the access denied error, In shock I clicked it again and Yep got the error. On the third click it worked. So I tried it again with the same results first two clicks error and the third worked. And teh simple Javascript code that is ugly as home made soap but now works is 我把图像放在表格上(就像我在网站上的几个地方。这就产生了访问被拒绝的错误,在震惊中我再次点击它并且得到错误。在第三次点击它工作。所以我再试一次同样的结果前两次点击错误,第三次工作。而简单的Javascript代码,作为自制肥皂丑,但现在工作是

var files= document.getElementById("newfiles");
files.onchange = addFiles;

function addFiles() {
    try {
        $("#fileupload").submit();
    } catch (e) {
        try {
            $("#fileupload").submit();
        } catch (e) {
            try {
                $("#fileupload").submit();
            } catch (e) {
                alert(e);
            }
        }
    }
};

Make sure also that you are not loading your jQuery asset from a CDN such as Google Hosted Libraries. 还要确保您没有从诸如Google Hosted Libraries之类的CDN加载您的jQuery资产。 Because the domain is different, that violates certain security protocols that Microsoft uses to protect against Cross Site Scripting in Internet Explorer. 由于域不同,这违反了Microsoft用于防止Internet Explorer中的跨站点脚本的某些安全协议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM