Bug Tracker

Ticket #2709 (closed bug: fixed)

Opened 1 year ago

Last modified 1 year ago

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

Reported by: eych Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.2.4 Component: core
Version: 1.2.3 Keywords:
Cc: Needs: Review

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

jquery.ie6.bug.test.suit.zip (29.0 kB) - added by eych 1 year ago.
Test suit which reproduces the problem, correct the paths in jquery.globalEval.html and open it in the browser.

Change History

Changed 1 year ago by eych

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

Changed 1 year 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.

Changed 1 year 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.

Changed 1 year ago by flesler

  • status changed from new to closed
  • resolution set to fixed

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

Applied at [5623].

Changed 1 year ago by eych

  • status changed from closed to reopened
  • resolution deleted

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 1 year ago by eych

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

Thanks.

Changed 1 year ago by flesler

  • status changed from reopened to closed
  • resolution set to fixed
  • milestone changed from 1.2.4 to 1.2.5

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

Changed 1 year ago by flesler

  • milestone changed from 1.2.5 to 1.2.4

I see now that all were kept as 1.2.4

Note: See TracTickets for help on using tickets.