Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

jquery - Preventing "SCRIPT5: Access is denied" error in IE

Scenario: Page A on A.com that has an IFrame containing Page B on B.com. Page B uses jQuery 1.10.1 and does not need to communicate with Page A.

Regardless of this fact, in IE9 and IE10, jQuery generates a "SCRIPT5: Access is denied." error and seemingly refuses to execute any jQuery at all. 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.

Is there a way to prevent this error from appearing (and inhibiting code execution) in IE9 and IE10? (FYI, other browsers similarly generate "access denied" errors, but they do not hinder code execution)


UPDATE:

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

The contents of the host page are (from the jsFiddle):

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

The contents of the iFramed page are:

<!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): enter image description here

Result in IE 9.0.8112 (Notice the omission of the message in the console):

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found a workaround. This appears to be a bug ("feature"?) in jQuery 1.10.1. Using jQuery 1.10.0, the error no longer occurs:

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! :)


UPDATE: Looks like this is a legit jQuery 1.10.1 bug: http://bugs.jquery.com/ticket/13980


UPDATE: According to @emanuele-greco, this is fixed in 1.10.2 and up. So, upgrading your version of jQuery will likely fix the problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...