Bug Tracker

Ticket #13936 (closed bug: fixed)

Opened 18 months ago

Last modified 10 months ago

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

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

Description

Case:

  1. IE 9 or 10, jQuery 1.9.1 or 2.0.0
  2. Select something from iframe
  3. Submit iframe's form
  4. 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/

Change History

comment:1 Changed 18 months ago by markelog

  • Owner set to markelog
  • Priority changed from undecided to low
  • Status changed from new to assigned
  • Component changed from unfiled to selector

Confirmed.

comment:2 Changed 18 months ago by dmethvin

#13938 is a duplicate of this ticket.

comment:3 Changed 18 months ago by Oleg

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: d0ca6096000a4a86f9a86f1deb0b498dd6dedf2c

comment:4 Changed 18 months ago by dmethvin

  • Milestone changed from None to 1.10.1/2.0.2

comment:5 Changed 18 months ago by dmethvin

See #13980 for followup.

comment:6 Changed 18 months ago by bigorangemachine@…

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

comment:7 Changed 18 months ago by anonymous

jQuery 1.10.1 Permission denied  http://jsfiddle.net/j3LaC/

comment:8 Changed 18 months ago by anonymous

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...

comment:9 Changed 18 months ago by anonymous

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...

comment:10 Changed 17 months ago by Mark Hagers

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

comment:11 Changed 17 months ago by Thomas

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

comment:12 Changed 16 months ago by Cody

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/

comment:13 Changed 16 months ago by dmethvin

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/

comment:14 Changed 16 months ago by anonymous

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);

comment:15 follow-up: ↓ 16 Changed 16 months ago by dmethvin

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

comment:16 in reply to: ↑ 15 Changed 16 months ago by anonymous

Replying to 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);

}

comment:17 Changed 15 months ago by haxorjim

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;
Last edited 15 months ago by haxorjim (previous) (diff)

comment:18 Changed 15 months ago by markelog

@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

comment:19 Changed 12 months ago by luked

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.

comment:20 Changed 12 months ago by dmethvin

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

comment:21 follow-up: ↓ 22 Changed 12 months ago by anonymous

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

comment:22 in reply to: ↑ 21 Changed 12 months ago by gibson042

Replying to anonymous:

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

#14535

comment:23 Changed 12 months ago by dh

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

comment:24 Changed 12 months ago by anonymous

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

comment:25 follow-up: ↓ 26 Changed 12 months ago by 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.

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.

comment:26 in reply to: ↑ 25 ; follow-up: ↓ 27 Changed 11 months ago by gibson042

Replying to 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.

comment:27 in reply to: ↑ 26 Changed 11 months ago by anonymous

Replying to gibson042:

Replying to 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.

comment:28 Changed 10 months ago by anonymous

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.

Note: See TracTickets for help on using tickets.