Bug Tracker

Opened 11 years ago

Closed 10 years ago

Last modified 7 years ago

#2923 closed bug (duplicate)

getScript and globalEvals fail in IE6 on jQuery 1.2.5 (includes fix)

Reported by: Crash1hd Owned by: brandon
Priority: critical Milestone: 1.3
Component: core Version: 1.2.5
Keywords: Cc:
Blocked by: Blocking:

Description

ok when using getScript() with a remote domain there are 2 errors in IE6 one it aborts the js file being returned and 2 it says invalid argument. I have noticed other bug reports indicating the same thing and they where patched in 1.2.5 however I dont think they where done right in this one

reference to other ticket:http://dev.jquery.com/ticket/2709

They indicated on using

'''head.insertBefore( script, head.firstChild );'''

which works but doesnt actually do what you want it to do which is add the code at the end. to make it add the code at the end you need to do the following

the insert at the end is fine with

'''head.insertChild(script)'''

thats ok the issue was with the head.removeChild(script) would fail what you want to do is this

'''script.parentNode.removeChild(script)'''

that allows the script to be added at the end of the head tag where you want it so that all other scripts run before and you can run stuff in the custom added script and works with basehref as well :)

that code above needs to be applied to every location where you use head.removeChild(script); so thats on lines: 644, 2621, 2672 see link below for reference to this code

Reference: http://groups.google.com/group/alt.comp.lang.javascript/browse_thread/thread/2380af22f06b05a6/475ae9c43505c581

that is only the first problem now to deal with why IE6 aborts the call to test.js on a remote server (no other browser does) well it seems to be an issue of timing so in the jQuery core on line 2677 is this code head.appendChild(script) i have replaced that with this

var IEAbortedFix = function(){
	head.appendChild(script);
}
setTimeout(IEAbortedFix,10);

and it seems that for the timeout it can be any number between 1 and 23. Anything less or more causes an error on the removeChild code

I have included a test case but you will need 2 servers and need to rename the calls to http://www.sitea.com and http://www.siteb.com to the 2 servers you are using.

Attachments (1)

IE6 jQuery getScript Fix.zip (59.9 KB) - added by Crash1hd 11 years ago.

Download all attachments as: .zip

Change History (8)

Changed 11 years ago by Crash1hd

comment:1 Changed 11 years ago by flesler

Owner: set to flesler
Status: newassigned

comment:2 Changed 11 years ago by Crash1hd

I need to add a note about this, not sure if you have had a chance to test it out yet but I have to note that once adding the above it actually broke in IE7 (I thought I had it working but then it wasnt) so what I realized is that the setTimeout delay was causing issues with the removal of the script tag as it had not been added yet to the dom from the delay in IE7 at least so by doing the following that fixed it :)

so on line 2678 where i had script.parentNode.removeChild(script) i had to update it to this

var IEAbortedFix2 = function(){
	script.parentNode.removeChild(script);
}
			
setTimeout(IEAbortedFix2,10);

by adding the same delay causes IE7 to wait for the removal till after the code is added. A fix for the fix lol

which also means that now you could probably set the delay time greater then 23 now as obviously that was the length of time that IE6 was taking to add the code any longer and it was calling the remove before the add happened!

comment:3 Changed 11 years ago by Crash1hd

I would also like to note that the 2nd issue is only ever an issue inside a click event as I have tried the same code above but on page load and its fine.

comment:4 Changed 11 years ago by rberger

It looks like this bug is also in 1.2.6. And that the same change needs to be done to line 2626 as well. This showed up for me when doing IE6 getJSON calls along the lines of:

var url = base_url + "/jsonfetch/" + message_file + "_json?format=json&cCallback=?";
$j.getJSON(url, function(data) {
         $j(content_jq).html(data.html);
}

comment:5 Changed 10 years ago by ricardoe

We are a small startup using heavily jQuery. I'm commenting on this issue because a fix to this is essential for our business. I've included the fixes and it works now, but we don't want to have a custom jQuery source. I hope this fix can make it in the next release.

comment:6 Changed 10 years ago by brandon

Owner: changed from flesler to brandon
Status: assignednew

comment:7 Changed 10 years ago by brandon

Resolution: duplicate
Status: newclosed

Consolidating this into #4378

Note: See TracTickets for help on using tickets.