2

我写了一个小部件,其中包含来自一个站点的 javascript,另一个站点。代码是:

<script type="text/javascript" src="http://www.easionline.com/min/?f=widget.js"></script> 

在 IE9 中,一切都显示完美,但在 IE8 中,我收到此错误:

Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2;
.NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0;
InfoPath.2)

Timestamp: Fri, 13 Jul 2012 07:20:30 UTC

Message: Access is denied.

Line: 7
Char: 73
Code: 0
URI: http://www.easionline.com/min/?f=widget.js

有人知道为什么 IE8 会给我一个消息被拒绝的问题吗?如果您想查看实现小部件的站点,请访问http://www.ham.co.za

如果您在没有缩小的情况下执行它:

<script type="text/javascript" src="http://www.easionline.com/widget.js"></script> 

我收到此错误:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2;
.NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0;
InfoPath.2)

Timestamp: Fri, 13 Jul 2012 07:49:41 UTC
Message: Access is denied.

Line: 98
Char: 3
Code: 0
URI: http://www.easionline.com/widget.js

与错误一致说:

96: var ajaxUrl = site_root+"ajax/widget/"+affid+"/"+category+"/"+numproducts;
97: 
98: obj.open("GET",ajaxUrl,true);
99: obj.send(null);

请注意,由于各种原因,我避免使用 Jquery 来完成这项任务。所以问题真的归结为:为什么这个 ajax 调用在 IE9 中有效,但在 IE8 中无效?

4

1 回答 1

0

这解决了我的问题:Access denied to jQuery script on IE

基本上,IE 要求您使用 XDomainRequest 而不是 XHR。所以我更换了:

obj=pullAjax();
  obj.onreadystatechange=function() {
    if(obj.readyState==4) {
        // etc
    }
}
obj.open("GET",ajaxUrl,true);
obj.send(null);

和:

xdr = new XDomainRequest(); 
xdr.onload=function()
{
    // etc
}
xdr.open("GET", thisUrl); 
xdr.send([data]); 

...但仅适用于 IE。我不得不使用 Javascript 来检测它是否是 IE,因为我不能将 jQuery 用于这个特定的项目。所以我用了这个:

var browserName=navigator.appName; 
if (browserName=="Microsoft Internet Explorer") ...

来源:http : //www.pageresource.com/jscript/jbrowse.htm

于 2012-07-13T12:40:25.540 回答