我编写了一个小部件,其中包括来自一个站点和另一个站点的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中无效?
这解决了我的问题:在IE 上拒绝访问jQuery脚本
基本上,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") ...
src:http://www.pageresource.com/jscript/jbrowse.htm