简体   繁体   中英

IE8 does not allow javascript reference, but IE9 does?

I wrote a widget that includes javascript from one site, on another. The code is:

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

In IE9, everything displays perfectly, but in IE8, I get this error:

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

Anybody know why IE8 would give me a message denied problem? If you want to see a site where the widget is implemented, visit http://www.ham.co.za

If you execute it without the minifying:

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

I get this error:

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

Line with the error says:

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

Please note, for various reasons I am avoiding Jquery for this task. So the question really boils down to: Why does this ajax call work in IE9 but not IE8?

This solved my problem: Access denied to jQuery script on IE

Basically, IE requires you to use XDomainRequest instead of XHR. So I replaced:

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

With:

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

... BUT only for IE. I had to use Javascript to detect if it is IE because I can't use jQuery for this specific project. So I used this:

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

src: http://www.pageresource.com/jscript/jbrowse.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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