Side navigation
#12266 closed bug (fixed)
Opened August 11, 2012 11:38AM UTC
Closed August 23, 2012 01:48AM UTC
Last modified December 29, 2013 03:51AM UTC
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
Attachments (0)
Change History (17)
Changed August 13, 2012 02:48PM UTC by comment:1
status: | new → open |
---|
Changed August 14, 2012 12:20AM UTC by comment:2
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.
Changed August 14, 2012 05:20PM UTC by comment:3
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.
Changed August 14, 2012 09:29PM UTC by comment:4
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.
Changed August 17, 2012 06:54AM UTC by comment:5
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
Changed August 20, 2012 08:46PM UTC by comment:6
_comment0: | 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"/>'); \ }}} → 1345495877601870 |
---|
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"/>');
More specifically, I had three external scripts, Google Analytics, G+ Button and Facebook Like button. I could leave Google Analytics, but either one of the G+ or FB Like button cause this error.
Changed August 20, 2012 08:53PM UTC by comment:7
The fix proposed by elijahmanor appeared to work in my case.
Changed August 21, 2012 03:30PM UTC by comment:8
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!
Changed August 23, 2012 01:48AM UTC by comment:9
resolution: | → fixed |
---|---|
status: | open → closed |
Fix #12266. IE9/10 says document[0] is document.frames[0]? Close gh-903.
Changeset: 10901f7d9fa6be01cc6b88cd94d279760b42a069
Changed August 24, 2012 05:27PM UTC by comment:10
I'm having the same bug using FB connect API.
Changed August 27, 2012 07:54PM UTC by comment:11
Is this jsFiddle test case, running on 1.8.0, an instance of the same bug?
Changed August 27, 2012 07:57PM UTC by comment:12
Replying to [comment:11 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.
Changed August 31, 2012 05:09PM UTC by comment:13
#12432 is a duplicate of this ticket.
Changed November 17, 2012 02:29PM UTC by comment:14
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) :)
Changed November 17, 2012 02:36PM UTC by comment:15
if(typeof(context[0].ownerDocument) != "undefined") { context = (context[0] || context).ownerDocument || context[0] || context; } else { context = context.ownerDocument || context[0] || context; }
Changed December 20, 2012 02:51PM UTC by comment:16
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; }
Changed December 29, 2013 03:51AM UTC by comment:17
Replying to [comment:16 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.