Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#12266 closed bug (fixed)

IE9 and jQuery 1.8 buildFragment method issue

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.0
Keywords: Cc:
Blocked by: Blocking:

Description

This error message started appearing after upgrading to jQuery 1.8 - "SCRIPT5: Access is denied. jquery-1.8.0.js, line 5927 character 2" (using IE9). After some debugging I found that:

  • it happens when creating jQuery object from html, like $('<div><div></div></div>')
  • this issue disappeared after removing 3rd party script (from addthis.com)

Demo - http://jsfiddle.net/Nxj9q/ - clicking 2nd link throws error using IE9

Change History (17)

comment:1 Changed 11 years ago by dmethvin

Status: newopen

Confirmed, but not understood! The third party script definitely is important, an earlier report in #12218 worked fine but from a test case I had to create.

comment:2 Changed 11 years ago by [email protected]

We "fixed" the issue by creating a JS wrapper object and writing to that instead:

http://jsfiddle.net/Nxj9q/2/

Obviously not ideal, but might provide a hint as to the solve.

comment:3 Changed 11 years ago by elijahmanor

So it looks like this issue has a conflict with the core028.js library used by jsFiddle.

If you recreate the issue listed in the ticket with JSBin, then the exception does not happen http://jsbin.com/onihul/4

The reason it fails in jsFiddle is that document[0] is somehow defined so the buildFragment method accesses the ownerDocument property https://github.com/appendto/jquery/blob/master/src/manipulation.js#L493 & gets an exception.

I'll see if I can find the unminified version of core028.js to see where things are going wrong.

comment:4 Changed 11 years ago by elijahmanor

Okay, so it wasn't jsFiddle. I did find the line of code in the addthis_widget.js that is causing the issue.

var h,t=navigator.userAgent.toLowerCase(),o=Math.floor(Math.random()*1000);
if(/msie/.test(t)&&!(/opera/.test(t))){
    n.innerHTML="<iframe id=\"_atssh"+o+"\" width=\"1\" height=\"1\" title=\"AddThis utility frame\" name=\"_atssh"+o+"\" src=\"\">";
    h=document.getElementById("_atssh"+o);
}

For some reason adding the iframe like the above is causing document[0] to be populated with the window object. Why? I have no idea and it's only happening if the browser is IE because it is browser sniffing.

Either, this library can update it's code so it doesn't inadvertently update the document or jQuery 1.8 can be more defensive in it's check inside of buildFragment method... so, instead of this

// Set context from what may come in as undefined or a jQuery collection or a node
context = context || document;
context = (context[0] || context).ownerDocument || context[0] || context;

we can change 1.8 to have something like this instead...

// Set context from what may come in as undefined or a jQuery collection or a node
context = context || document;
context = context instanceof jQuery ? context[0] : context;
context = context.ownerDocument || context;

I'll work on getting some unit tests put together and make a pull request with the above change if you all think that is a good thing.

comment:5 Changed 11 years ago by Tim

Confirmed that I also get this error on that exact same line in IE9 only - it doesn't appear in IE8 for me however only Ie9.

SCRIPT5: Access is denied. jquery.js, line 5927 character 2

comment:6 Changed 11 years ago by thomthom

I'm also seeing this. An in my case I have G+ and FB javascript on my page. When I remove these then everything works fine. But when these third party scripts are loaded I get Access Denied on:

$balloon = $('<div id="purchase_help" class="balloon"/>');
Version 0, edited 11 years ago by thomthom (next)

comment:7 Changed 11 years ago by thomthom

The fix proposed by elijahmanor appeared to work in my case.

comment:8 Changed 11 years ago by elijahmanor

I have added a Pull Request for this issue. It took some time trying to figure out how to create a reduced unit test without pulling in that 3rd party script. I ended up using the testIframeWithCallback helper function to inject a cross-domain iframe before DOM Ready.

The fix above also accounts for another patch that was made previously so I was able to remove that code making the overall size of the Pull Request smaller than when it started!

https://github.com/jquery/jquery/pull/903

comment:9 Changed 11 years ago by Elijah Manor

Resolution: fixed
Status: openclosed

Fix #12266. IE9/10 says document[0] is document.frames[0]? Close gh-903.

Changeset: 10901f7d9fa6be01cc6b88cd94d279760b42a069

comment:10 Changed 11 years ago by anonymous

I'm having the same bug using FB connect API.

comment:11 Changed 11 years ago by Alan Hogan

Is this jsFiddle test case, running on 1.8.0, an instance of the same bug?

http://jsfiddle.net/alanhogan/YNWDc/

comment:12 in reply to:  11 Changed 11 years ago by dmethvin

Replying to Alan Hogan:

Is this jsFiddle test case, running on 1.8.0, an instance of the same bug?

http://jsfiddle.net/alanhogan/YNWDc/

Nope. Please don't hitch onto a closed ticket. Ask for help on a forum, your code isn't right.

comment:13 Changed 11 years ago by dmethvin

#12432 is a duplicate of this ticket.

comment:14 Changed 10 years ago by Anthonus

I hope this helps someone... I fixed the above problem by adding changing line 5927 to the following:

if(typeof(context[0].ownerDocument) != "undefined") {

context = (context[0]
context).ownerDocument context[0] context;

} else {

context = context.ownerDocument
context[0] context;

}

Seem to work... (I am not a jQuery expert, but I am a programming one) :)

comment:15 Changed 10 years ago by [email protected]

        if(typeof(context[0].ownerDocument) != "undefined") {
           context = (context[0] || context).ownerDocument || context[0] || context;
        } else {
          context = context.ownerDocument ||  context[0] || context;
        }

comment:16 Changed 10 years ago by mars

well, this errors in firefox for me, while this seems to fix the issue:

	if (context[0] && typeof(context[0].ownerDocument) != "undefined") {
		context = (context[0] || context).ownerDocument || context[0] || context;
	} else {
		context = context.ownerDocument ||  context[0] || context;
	}

comment:17 in reply to:  16 Changed 9 years ago by anonymous

Replying to mars:

well, this errors in firefox for me, while this seems to fix the issue:

	if (context[0] && typeof(context[0].ownerDocument) != "undefined") {
		context = (context[0] || context).ownerDocument || context[0] || context;
	} else {
		context = context.ownerDocument ||  context[0] || context;
	}

wow, I was skeptical about this code since I tried all and search a solution all over the web, and more even this discuss was more then a year ago. It's work like a charm, you do not conceivable about how much you helped me, thanks a lot!

Note: See TracTickets for help on using tickets.