Internet Explorer 中的 JavaScript 错误“访问被拒绝”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17214053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 07:30:48  来源:igfitidea点击:

JavaScript error "Access is denied" in internet explorer

javascriptinternet-explorer

提问by Sid

I am getting this error when i run my webpage in IE(the code runs fine in other browsers).

当我在 IE 中运行我的网页时出现此错误(代码在其他浏览器中运行良好)。

This is the HTML code:

这是 HTML 代码:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<--- some html code --->
<iframe src='http://localhost/page1.php' style="background: transparent; overflow: hidden; height: 210px; width: 390px;" frameborder="0"  />
</body>
</html>

This is page1.php

这是page1.php

<!DOCTYPE html>
<html>
<body>
<form action="usercheck.php" method="POST">
USERNAME:<input name="uname" id="uname" type="text" maxlength="12" required/>
<input type="submit" value="Submit">
</form>
</body>
</html>

This is usercheck.php

这是 usercheck.php

<?php
//some php code    
?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<--- some html code --->
</body>
</html>

The problem is that when reach usercheck.phpafter clicking on submit button in page1.phpi get the error http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js. Access is denied.Here is an image of the error: http://i.stack.imgur.com/diCoF.jpg. Then consequently i get the error that '$' symbol is not defined(which is due to the failure to load the jquery library).

问题是当我usercheck.php点击提交按钮后到达时page1.php出现错误http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js. Access is denied.这是错误的图像:http: //i.stack.imgur.com/diCoF.jpg。然后,我收到未定义“$”符号的错误(这是由于无法加载 jquery 库)。

EDIT- I have tried including the jquery file in my server but still the error is comming. I have also tried this code for usercheck.php:

编辑 - 我已经尝试在我的服务器中包含 jquery 文件,但仍然出现错误。我也为 usercheck.php 尝试过这段代码:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
/*! jQuery v1.10.1 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
//@ sourceMappingURL=jquery.min.map
//and the rest of the jquery library...
</script>
</head>
<body>
<--- some html code --->
</body>
</html>

The error i am getting this time is this:http://i.stack.imgur.com/hR9aN.jpg(The original name of usercheck2.php is rscheck.php in my server). Then consequently i get the error that '$' symbol is not defined(which is due to the failure to load the jquery library). If i directly open the contents of page1.php (by the url- localhost/page1.php) then everything works fine.

这次我得到的错误是这样的:http: //i.stack.imgur.com/hR9aN.jpg(usercheck2.php 的原始名称是我服务器中的 rscheck.php)。然后,我收到未定义“$”符号的错误(这是由于无法加载 jquery 库)。如果我直接打开 page1.php 的内容(通过 url-localhost/page1.php),那么一切正常。

This is the only code for which i am using JQuery:

这是我使用 JQuery 的唯一代码:

if($("#pret").contents().text().search("NAMECHECK: NOTAVALIBLE")!=-1)

I could exclude jquery only if i can convert this code to javascript.

仅当我可以将此代码转换为 javascript 时,我才能排除 jquery。

采纳答案by Sid

Here is the working solution to my question. The reason i wanted jquery was that i wanted to run this code:

这是我的问题的有效解决方案。我想要 jquery 的原因是我想运行这个代码:

if($("#pret").contents().text().search("NAMECHECK: NOTAVALIBLE")!=-1)

I removed jquery library and used this javascript to do the same:

我删除了 jquery 库并使用这个 javascript 来做同样的事情:

var n=document.getElementById("pret").innerHTML.search("NAMECHECK: NOTAVALIBLE");
if(n != -1)

Now there is no error in the page and i am able to do what i wanted. So the error was caused as jquery library was not able to load in the webpage. But i dont know why even after downloading the jquery library in my server i was getting the same error ie. 'Access is denied'.

现在页面中没有错误,我可以做我想做的事。所以错误是由于jquery库无法在网页中加载而引起的。但我不知道为什么即使在我的服务器中下载了 jquery 库后,我也遇到了同样的错误,即。'访问被拒绝'。

回答by Emanuele Greco

This is a legit jQuery 1.10.1bug: http://bugs.jquery.com/ticket/13980.
Using jQuery 1.10.0, or 1.10.2the error no longer occurs.

这是一个合法的jQuery 1.10.1错误:http: //bugs.jquery.com/ticket/13980
使用jQuery 1.10.0,或1.10.2不再出现错误。

回答by Saturnix

Try to download jquery.min.jsto your server and include it from there. For example:

尝试下载jquery.min.js到您的服务器并从那里包含它。例如:

<script type="text/javascript" src="/jquery.min.js"></script>.

<script type="text/javascript" src="/jquery.min.js"></script>.

It looks like internet explorer can't access the resource: downloading it to your own server might solve the issue.

Internet Explorer 似乎无法访问该资源:将其下载到您自己的服务器可能会解决该问题。

回答by Iurii.K

The reason is in the iframe. As jQuery is loaded into the iframe from the external host, each time when you are trying to use any jQuery function in your main/outer html file, IE throws the error due to security reasons.

原因在iframe. 由于 jQuery 从外部主机加载到 iframe 中,每次当您尝试在主/外部 html 文件中使用任何 jQuery 函数时,IE 都会出于安全原因抛出错误。

1)Either upload jQuery to your server,

1)要么将 jQuery 上传到您的服务器,

2)or include it in main html file only (not in iframe).

2)或仅将其包含在主 html 文件中(不在 iframe 中)。