Skip to main content

Bug Tracker

Side navigation

#2709 closed bug (fixed)

Opened April 17, 2008 11:16PM UTC

Closed May 21, 2008 06:09PM UTC

Last modified March 14, 2012 05:40AM UTC

globalEval works incorrectly in IE6 if the current page has <base href> tag in the HEAD

Reported by: eych Owned by:
Priority: major Milestone: 1.2.4
Component: core Version: 1.2.3
Keywords: Cc:
Blocked by: Blocking:
Description

That's a weird problem, but I've experienced it on a production site and was able to reproduce it in a simple test (attached to this ticket).

The problematic scenario is this:

1. You have a page (let's call it A) with <base href="http://domain/path/" /> in the HEAD. And jQuery loaded as well.

2. On the same page you have a button which if clicked will make an Ajax call to another page (let's call it B) and will insert the response in a div inside page A.

3. This page B has usual HTML content (a bunch of divs) and a JS script block, which has code that should be executed when the Ajax response is added to page A after the Ajax response finishes.

In all browsers this works fine, except IE6. In IE6 I always get "Invalid argument" error which points to

head.removeChild( script );

line in globalEval method of jQuery (line 655).

I did a lot of testing an eventually nailed down the problem to the <base href> line in the head of the page. If it's there, I get an error in IE6, if it's not then everything's fine.

Somewhat accidentally I was able to come up with a solution which fixes this weird behavior of IE6:

In globalEval method on line 654 I simply replaced

head.appendChild( script );

with

head.insertBefore( script, head.firstChild );

and the problem vanished. Please look at the attached test case (the paths should be corrected in it in jquery.globalEval.html file and this file should be opened in the browser).

Hopefully this could be officially fixed in the next jQuery version.

Attachments (1)
  • jquery.ie6.bug.test.suit.zip (29.0 KB) - added by eych April 17, 2008 11:17PM UTC.

    Test suit which reproduces the problem, correct the paths in jquery.globalEval.html and open it in the browser.

Change History (9)

Changed April 19, 2008 12:49PM UTC by eych comment:1

Something that occurred later to me is that my solution just adds the script in the head BEFORE the <base href> part and this fixes the problem in IE6. The standard jQuery logic in this part adds script as the last child of HEAD, which means that it is placed after <base href> and this is not working correctly in IE6.

I also forgot to mention in my initial bug description, that the script which has arrived from an Ajax request actually executes fines in IE6 as well in this situation (so the head.appendChild(script) line works in jQuery). And the error appears only when jQuery tries to remove that script from the head with head.removeChild.

Changed May 05, 2008 11:58AM UTC by anojszewski comment:2

I'm confirming this bug and the above solution. I have similar setup with <base href> and AJAX loading content with in-line <script> tag. Changing line 654 helped.

Changed May 16, 2008 06:37PM UTC by flesler comment:3

resolution: → fixed
status: newclosed

Ok, easy change, if it works.. why not.

Applied at [5623].

Changed May 20, 2008 04:41PM UTC by eych comment:4

resolution: fixed
status: closedreopened

Thanks for deciding to fix this. But I can't find the fix in the uncompressed version of jQuery 1.2.4 which I've just downloaded from http://jquery.com/. It still has exactly the same lines in the problematic place:

head.appendChild( script );

head.removeChild( script );

Changed May 21, 2008 02:26PM UTC by eych comment:5

The patch was applied in 1.2.5 release. So this ticket can be closed.

Thanks.

Changed May 21, 2008 06:09PM UTC by flesler comment:6

milestone: 1.2.41.2.5
resolution: → fixed
status: reopenedclosed

Yeah.. that 1.2.4 problem was odd. Glad it works now.

Changed May 21, 2008 06:16PM UTC by flesler comment:7

milestone: 1.2.51.2.4

I see now that all were kept as 1.2.4

Changed March 11, 2011 05:38AM UTC by hisland@qq.com comment:8

in ie6:

if there is a base tag which self-closed,like this: <base href="some-url" />

then, head.appendChild(script), the script.parentNode is base not head,so head.removeChild( script ) goes wrong!

you can do it like this: script.parentNode.removeChild( script ),it works!

if the base tag is not self-closed,like this: <base href="some-url"></base>,there isn't the bug.

other browser works good!

you can see this page

https://github.com/hisland/hdl-assets/blob/master/tests/ie6-appendChild-insertBefore/index.html

Changed March 11, 2011 06:10AM UTC by hisland@qq.com comment:9

i just download the attachment, and test it.

after change the url to be right, and the page can be run in my local envirement,i try to add 'alert(script.parentNode.tagName);' between jquery.js's line 654,655.

then in ie6, i got a alter shows BASE, not HEAD

then i change base tag to <base href="my-local-url" ></base>, it shows HEAD!

same as my previous post!