Bug Tracker

Modify

Ticket #13378 (closed bug: wontfix)

Opened 15 months ago

Last modified 13 months ago

ie8 & ie9 iframe - .filter(":focus") - document.activeElement returns unspecified error.

Reported by: muzzamo Owned by: timmywil
Priority: low Milestone: 1.10
Component: selector Version: 1.9.0
Keywords: Cc: timmywil
Blocking: Blocked by:

Description

Unfortunately I am unable to put this into jsfiddle/jsbin due to issues with scripts in iframes on both of these sites. It can be reproduced if you place the following two files in a folder on the file system and open outer.html in ie9:

outer.html

<!DOCTYPE html>
<html lang="en">
<body>

	<div style="border: 1px solid black">
    <iframe src="inner.html" style="width:1024px; height:768px;"></iframe>

    </div>
   
</body>
    
</html>

inner.html

<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<!--<script src="http://code.jquery.com/jquery-git.js"></script>-->
</head>
<body>

<a id="link" href="http://www.google.com">google</a> 
<script>
       $("#link").filter(":focus");
</script>
</html>

To make sure that internet explorer executes scripts when loaded this way go to internet options -> advanced -> security -> "Allow active content to run in files on My Computer*". Then when you load the page in ie, a popup will appear at the bottom saying "Internet explorer restricted this webpage from running scripts or ActiveX controls.", click "Allow blocked content".

Make sure the script debugger is enabled (F12 developer tools -> script -> start debugging).

This is occurring on line 4869 of jquery-1.9.0.js. This also occurred on jquery 1.8.x. This is also occurring in jquery-git.js v 2013-2-3 on line 4877.

This occurs on ie8 and ie9 (ie7, ie10 not tested), and does not occur on firefox and chrome.

I believe this was first reported in jquery UI ticket 8443 ( http://bugs.jqueryui.com/ticket/8443) which was closed due to not enough information. The issue applies to jquery core.

The workaround for this bug is to add the following to the iframe.html file:

<script>
             jQuery(function () { document.documentElement.focus(); });
        </script>

This issue was first reported as a defect in kendo UI v2012.3.1315 in the menu widget, which depends on JQuery 1.8.x.

Change History

comment:1 Changed 15 months ago by anonymous

I have now created a jsfiddle for this as well.

Make sure the script debugger is enabled in ie.

 http://jsfiddle.net/muzzamo/2taTW/

comment:2 Changed 15 months ago by gibson042

  • Cc timmywil added
  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to selector

The exception is thrown on access of document.activeElement in the framed page, and document.hasFocus() frustratingly returns true. We can either stick a try…catch in the ":focus" filter or wontfix this ticket, but I don't see a third option.

comment:3 Changed 14 months ago by azkme

One remark on this one: it doesn't always occur though. If I open the page in IE9 on the webserver itself, there are no problems for me. This only occurs when I try opening a page from another location as the webserver (beats me).

comment:4 follow-up: ↓ 6 Changed 14 months ago by nikolay.r.rusev@…

I use to have the same issue. As far as my experience I found two workarounds for this problem:

  • call document.documentElement.focus() - this will somehow force document invalidation
  • use document.documentElement.activeElement instead of document.activeElement

Hope it help someone.

comment:5 Changed 14 months ago by johnny_reilly@…

I've been experiencing a very similar issue with an IFrame on IE when calling the following bit of code:

$("input[autofocus]").focus();

This blows up on line 3254 of jquery-1.9.1.js, apparently on the following command:

(this !== document.activeElement)

Would be great if this could be fixed....

comment:6 in reply to: ↑ 4 Changed 13 months ago by anonymous

Replying to nikolay.r.rusev@…:

I use to have the same issue. As far as my experience I found two workarounds for this problem:

  • call document.documentElement.focus() - this will somehow force document invalidation
  • use document.documentElement.activeElement instead of document.activeElement

Hope it help someone.

===============

  • use document.documentElement.activeElement instead of document.activeElement

This works for me. Thanks for the post! Van Thi

comment:7 Changed 13 months ago by mattfaus@…

This has caused several high-priority problems for us in the past few weeks. I think the priority of this bug should be escalated.

Thanks to those who have posted workarounds though!

comment:8 Changed 13 months ago by xfinx

Thanks for the workarounds! Recently upgraded to 1.9.1 and our gallery (which is loaded in an iframe) stopped working. I would love to see this one fixed.

Thanks!

comment:9 Changed 13 months ago by timmywil

  • Owner set to timmywil
  • Status changed from open to assigned

comment:10 Changed 13 months ago by Timmy Willison

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

Update Sizzle: use documentElement in focus selector. Fixes #13378.

Changeset: aadae5058a44e745ebdbee5d5333402699326188

comment:11 Changed 13 months ago by dmethvin

  • Milestone changed from None to 1.10

comment:12 Changed 13 months ago by timmywil

  • Status changed from closed to reopened
  • Resolution fixed deleted

comment:13 Changed 13 months ago by timmywil

Unfortunately, the test that made sure that it didn't throw an error was passing because documentElement.activeElement is just undefined. We will not be fixing this because the only solutions are either a try/catch or calling document.focus(), neither of which we are willing to do. However, we had bypassed QSA for all :focus selectors due to a Chrome bug. We will instead let :focus always pass through QSA so IE doesn't throw an error (except in a few edge cases), but Chrome will be wrong sometimes.

comment:14 Changed 13 months ago by timmywil

  • Status changed from reopened to closed
  • Resolution set to wontfix

comment:15 Changed 13 months ago by m_gol

If Chrome has a bug here it should probably be reported to them and linked to this meta bug:
 https://code.google.com/p/chromium/issues/detail?id=176671
(I'm not doing it myself because I don't know the details of this bug).

Fortunately, if/when they fix it this problem just disappears for us because of Chrome rapid release pace; can't say the same about IE.

Last edited 13 months ago by m_gol (previous) (diff)

comment:16 Changed 13 months ago by timmywil

The bug has been fixed in browsers that jQuery supports. It is only an issue for Sizzle.

comment:17 Changed 13 months ago by m_gol

Ah, ok.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.