Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 8 years ago

#2709 closed bug (fixed)

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.
  1. 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.
  1. 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 12 years ago.
Test suit which reproduces the problem, correct the paths in jquery.globalEval.html and open it in the browser.

Download all attachments as: .zip

Change History (10)

Changed 12 years ago by eych

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

comment:1 Changed 12 years ago by eych

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.

comment:2 Changed 12 years ago by anojszewski

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.

comment:3 Changed 12 years ago by flesler

Resolution: fixed
Status: newclosed

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

Applied at [5623].

comment:4 Changed 12 years ago by eych

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 );

comment:5 Changed 12 years ago by eych

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

Thanks.

comment:6 Changed 12 years ago by flesler

Milestone: 1.2.41.2.5
Resolution: fixed
Status: reopenedclosed

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

comment:7 Changed 12 years ago by flesler

Milestone: 1.2.51.2.4

I see now that all were kept as 1.2.4

comment:8 Changed 9 years ago by hisland@…

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

comment:9 Changed 9 years ago by hisland@…

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[[BR]] same as my previous post!

Note: See TracTickets for help on using tickets.