Skip to main content

Bug Tracker

Side navigation

#13936 closed bug (fixed)

Opened May 24, 2013 12:26PM UTC

Closed May 29, 2013 01:47PM UTC

Last modified January 30, 2014 03:02PM UTC

SCRIPT70 Permission denied in selectors after iframe was submitted in IE9-10, jQuery 1.9.1 and 2.0.0

Reported by: yaremenkofv@gmail.com Owned by: markelog
Priority: low Milestone: 1.10.1/2.0.2
Component: selector Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:
Description

Case:

0. IE 9 or 10, jQuery 1.9.1 or 2.0.0

1. Select something from iframe

2. Submit iframe's form

3. Select something from body or iframe

Result: SCRIPT70: Permission denied

Example:

body

<iframe src="/iframe.html"></iframe>
<input id="button" type="button" value="Submit iframe"/>

iframe.html body

<form method="get">
  <input name="hidden" type="hidden" value="123"/>
</form>

init code

$(function () {
	$('input#button').click(function () {
		$('span');
		$('iframe').contents().find('form')[0].submit();
	});
});

$('span') fails after second button click.

Example on jsFiddle: http://jsfiddle.net/G8NCw/

Attachments (0)
Change History (28)

Changed May 26, 2013 11:06AM UTC by markelog comment:1

component: unfiledselector
owner: → markelog
priority: undecidedlow
status: newassigned

Confirmed.

Changed May 27, 2013 04:27PM UTC by dmethvin comment:2

#13938 is a duplicate of this ticket.

Changed May 29, 2013 01:47PM UTC by Oleg comment:3

resolution: → fixed
status: assignedclosed

Sizzle Update: fix #13936 - iframe reload should not affect Sizzle.

Changeset: d0ca6096000a4a86f9a86f1deb0b498dd6dedf2c

Changed May 30, 2013 06:23PM UTC by dmethvin comment:4

milestone: None1.10.1/2.0.2

Changed June 03, 2013 03:48PM UTC by dmethvin comment:5

See #13980 for followup.

Changed June 12, 2013 03:12PM UTC by bigorangemachine@hotmail.com comment:6

IE8 still generates 'permission' denied error when inside an iFrame.

<iframe src="/framechild.html"></iframe>

Inside framechild.html

<!--stuff up here-->
<script src="assets/js/jquery.1.10.1.js"></script>
<!-- ERROR IS GENERATED in IE8-->

Changing line 1513 to sizzles new code will correct this issue

if ( parent && parent.frameElement ) {

to

if ( parent && parent.attachEvent && parent !== parent.top ) {

will fix this issue

Changed June 13, 2013 03:11AM UTC by anonymous comment:7

jQuery 1.10.1 Permission denied

http://jsfiddle.net/j3LaC/

Changed June 14, 2013 07:57AM UTC by anonymous comment:8

We are having the same SCRIPT70 Permission denied issue (in IE only (7,8,9 & 10)).

Basicly we have an iframe that either gets reloaded (because a form (post) submit has happend), or gets redirected to a different page.

(note, all pages we load in the iframe are on the exact same domain, not even on a subdomain but the exact same domain).

Each time the iframe fires its "onload" event, we call a function which then assigns click events to buttons inside the iframe.

example, we have this on our iframe:

onload="popupLoaded(this);"

We then have something like:

function popupLoaded(obj){
var iframecontents = $(obj.contentDocument);
//or, we also tried it like this
var iframecontents2 = $("#iframeID").contents();

iframecontents.find("#mybutton").click(function(){
alert("Clicked me!");
});

iframecontents2.find("#mybutton").click(function(){
alert("Clicked me! (2)");
});
}

In IE, when the iframe loads for the first time, these clicks work.

But when the iframe gets reloaded or redirected to a different page, it throws the permission denied because for some reason we can't seem to access the iframe's contents anymore.

!! (wierd) FIX


Note that all of this is done with jQuery 1.9 or 1.10, both give the same problems.

After changing it to an old version of jQuery, version 1.4.1, this seems to be fixed, no errors are thrown and the clicks all function propperly...

Changed June 14, 2013 02:34PM UTC by anonymous comment:9

Hi, I'm the author of comment above (NR. 8),

We've found out, and fixed, what caused our SCRIPT70 Permission Denied error.

Here's what we did:

When clicking on an icon we insert an iframe on the page inside a div called popup.

$("#popup").html('<iframe src="'+ url +'" onload="popupLoaded(this);"></iframe>');

The iframe then loads our page which has several div's on it, each with their own "hidden" input. For each of these div's we want the entire div to be clickable, so we create the click event on the div.

This is the function that gets called when the iframe is loaded

function popupLoaded(obj){
	//Get the iframe's content
	var contents = $(obj.contentDocument);

	//Make the click call
	contents.find(".divname").click(function(){
		//This next line causes the script70 error in IE
		var myHiddenValue = $(this).find(".hiddenval").val();

		//Then we go on doing stuff with this value...
	});
}

Here's what we had to do to fix it:

function popupLoaded(obj){
	//Get the iframe's content
	var contents = $(obj.contentDocument);

	//Make the click call
	contents.find(".divname").click(function(e){
		//var myHiddenValue = $(this).find(".hiddenval").val();

		//Alternative way to grabbing the hidden value
		var myValObject = $('<div/>').html(e.currentTarget.innerHTML).contents();
		var myHiddenValue = myValObject.find(".hiddenval").val();

		//Now we were able to get the value without any problems
		//Then we go on doing stuff with this value...
	});
}

So basicly we had to grab the innerhtml of the object we clicked (being the div) and turn it into a jquery object.

Then we were able to perform a .find() in this object and get the value, without having that annoying permission denied error in IE...

Changed June 20, 2013 04:04PM UTC by Mark Hagers comment:10

The fiddle example above still gives the error in IE 10 (if you set the jquery version to 1.10.1).

We have a large project with 3rd party js library that triggers the issue.

Is this something that will be fixed in jQuery eventually? or should the 3rd party fix this?

For the moment we'll migrate back to 1.9.x

Changed July 02, 2013 03:53PM UTC by Thomas comment:11

I too am still getting this error with 1.10.1 in IE8-10

Changed July 26, 2013 07:49PM UTC by Cody comment:12

I can confirm that these fiddle examples [1,2] in this thread still cause the issue in 1.10.1 & 2.0.2. Also comment 8 and 9 exactly mirror my experience discovering this bug and working around the issue.

[1] http://jsfiddle.net/G8NCw/

[2] http://jsfiddle.net/j3LaC/

Changed July 26, 2013 07:56PM UTC by dmethvin comment:13

Thomas and Cody, does it work when you use the most recent released version?

http://blog.jquery.com/2013/07/03/jquery-1-10-2-and-2-0-3-released/

Changed July 30, 2013 04:53PM UTC by anonymous comment:14

I got similar issue in >=IE8. I have a popup dialog from an ifame content. On submitting, the following statement results in Permission denied error in Jquery1.9.1, and 1.10.2.

dialog = $(window.top).attr(window.frameElement.id);

Changed July 30, 2013 05:12PM UTC by dmethvin comment:15

You can't call .attr() on a window, it's only for DOM elements.

Changed July 30, 2013 05:58PM UTC by anonymous comment:16

Replying to [comment:15 dmethvin]:

You can't call .attr() on a window, it's only for DOM elements.

I am calling .attr() on $(window). In any case, it used to work on the old version (jquery.1.5.2):

var dialog = $(window.top).attr(window.frameElement.id);

if (!dialog) {

dialog = $(window.parent).attr(window.frameElement.id);

}

Changed August 21, 2013 05:32PM UTC by haxorjim comment:17

_comment0: If you're stuck on 1.9.1 because of IE, you could always bypass jquery for this purpose. The following code worked for us. In our case we needed the html, but the premise is the same. \ \ \ {{{ \ var iframe = document.getElementById('iframe'); \ var html = iframe.contentDocument.getElementsByTagName('body')[0].innerHTML; \ }}}1377106452159347

If you're stuck on 1.9.1 because of IE, you could always bypass jquery for this purpose. The following code worked for us. In our case we needed the html, but the premise is the same.

var iframe = document.getElementById('frameId');
var html = iframe.contentDocument.getElementsByTagName('body')[0].innerHTML;

Changed August 21, 2013 05:43PM UTC by markelog comment:18

@haxorjim you could always update to 1.10.2, which has full support for IE6+, if you have migration problems, you could use https://github.com/jquery/jquery-migrate/, also this might be helpful too

Changed November 13, 2013 03:55AM UTC by luked comment:19

This issue has re-arisen in IE11. The fix committed for this ticket does not activate because it looks for window.attachEvent which has been removed from IE11.

Changed November 13, 2013 03:59AM UTC by dmethvin comment:20

@luked, please open a new ticket with a test case. Thanks!

Changed November 13, 2013 06:14AM UTC by anonymous comment:21

Can someone link to the new ticket? Would like to follow it, as I'm having the same issue in IE11

Changed November 13, 2013 05:51PM UTC by gibson042 comment:22

Replying to [comment:21 anonymous]:

Can someone link to the new ticket? Would like to follow it, as I'm having the same issue in IE11

#14535

Changed November 21, 2013 02:23PM UTC by dh comment:23

this is a big issue preventing use of jquery in salesforce!

Changed November 27, 2013 02:35PM UTC by anonymous comment:24

same problema when clone object:

var eRows = $(rows).clone();

SCRIPT5007: No se puede obtener la propiedad 'ownerDocument' de referencia nula o sin definir

Archivo: jquery-1.9.1.js, Línea: 4392, Columna: 2

Changed December 12, 2013 12:27PM UTC by thomas@wolkenstein.com comment:25

Due to the preferredDoc variable introduced in jQuery 1.9 i can not use this version and latter in my project that uses iframes. The variable caches a document object that becomes obsolete when the iframes is reloaded and Internet Explorer throws SCRIPT70: Permission denied.

Maybe my project is to blame as well because I reuse the jQuery object (sometimes) between frames. But I think it is a major design flaw to cache the document object. JQuery should not do this - at least not inside a frame or an iframe.

Changed December 12, 2013 07:59PM UTC by gibson042 comment:26

Replying to [comment:25 thomas@…]:

Due to the preferredDoc variable introduced in jQuery 1.9 i can not use this version and latter in my project that uses iframes. The variable caches a document object that becomes obsolete when the iframes is reloaded and Internet Explorer throws SCRIPT70: Permission denied.

Hopefully you are testing with our betas, because both this issue and its sister #14535 have already been resolved.

Changed December 13, 2013 01:32PM UTC by anonymous comment:27

Replying to [comment:26 gibson042]:

Replying to [comment:25 thomas@…]: > Due to the preferredDoc variable introduced in jQuery 1.9 i can not use this version and latter in my project that uses iframes. The variable caches a document object that becomes obsolete when the iframes is reloaded and Internet Explorer throws SCRIPT70: Permission denied. Hopefully you are testing with our betas, because both this issue and its sister #14535 have already been resolved.

I have just test with jquery-1.11.0-beta2.js and I had the same SCRIPT70: Permission denied error. I have tracked down the reason:

The jquery library attaches the onbeforeunload event to the iframe to remove the reference to the obsolete document object from the document variable inside jquery. The beforeunload event is not fired when window.location is used to navigate in the iframe. On my page I set window.location.href in the onload event of the iframe.

Changed January 30, 2014 03:02PM UTC by anonymous comment:28

I had a similar issue except I was creating an iframe and appending it to the document. IE used to allow

$('<iframe .../>').appendTo($('body'))

, but newer versions will throw "Permission Denied" error. So, proper way is

var iFrame = document.createElement('iframe');
...
document.body.appendChild(iFrame);

When doing that I no longer get IE "Permission Denied" error.