#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
Status: | new → open |
---|
comment:2 Changed 11 years ago by
We "fixed" the issue by creating a JS wrapper object and writing to that instead:
Obviously not ideal, but might provide a hint as to the solve.
comment:3 Changed 11 years ago by
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
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
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
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"/>');
comment:8 Changed 11 years ago by
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!
comment:9 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | open → closed |
Fix #12266. IE9/10 says document[0] is document.frames[0]? Close gh-903.
Changeset: 10901f7d9fa6be01cc6b88cd94d279760b42a069
comment:11 follow-up: 12 Changed 11 years ago by
Is this jsFiddle test case, running on 1.8.0, an instance of the same bug?
comment:12 Changed 11 years ago by
Replying to Alan Hogan:
Is this jsFiddle test case, running on 1.8.0, an instance of the same bug?
Nope. Please don't hitch onto a closed ticket. Ask for help on a forum, your code isn't right.
comment:14 Changed 10 years ago by
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
if(typeof(context[0].ownerDocument) != "undefined") { context = (context[0] || context).ownerDocument || context[0] || context; } else { context = context.ownerDocument || context[0] || context; }
comment:16 follow-up: 17 Changed 10 years ago by
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 Changed 9 years ago by
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!
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.