Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit:</strong> This solution has been implemented where <a href="https://github.com/joelpurra/emulatetab/issues/2" rel="nofollow noreferrer">the problem was first found</a>, in <a href="http://joelpurra.github.com/emulatetab" rel="nofollow noreferrer">EmulateTab</a>. See <a href="https://github.com/joelpurra/emulatetab/blob/master/src/emulatetab.joelpurra.js#L97" rel="nofollow noreferrer">getFocusedElement()</a>.</p> <hr> <p>Found a solution myself, after a break from coding - but it is not a very <em>clean</em> solution. It is basically the <a href="https://stackoverflow.com/a/9301634/907779">same solution</a> suggested by <a href="https://stackoverflow.com/users/182705/neil">@Neil</a> while I first wrote this post.</p> <p>Try <a href="http://jsfiddle.net/joelpurra/bzsv7/2/" rel="nofollow noreferrer">the updated jsFiddle version with focus listeners and try-catch logic</a> in Firefox. It combines <code>:focus</code>, <code>document.activeElement</code> and document level focus listeners that keep track of the last "known" focused element.</p> <h2>Function to find focused element</h2> <pre><code>// Comined function to get the focused element trying as long as possible. // Extra work done trying to avoid problems with security features around // &lt;input type="file" /&gt; in Firefox (tested using 10.0.1). function getFocused() { // Try the well-known, recommended method first. var $focused = $(':focus'); if ($focused.size() === 0) { try { // Fall back to a fast method that might fail. // Known to fail for Firefox (tested using 10.0.1) with // Permission denied to access property 'nodeType'. $focused = $(document.activeElement) } catch (error1) { warnToConsole("Could not use document.activeElement", document.activeElement, error1); if (lastFocusedElement !== null) { try { // As a last resort, use the last known focused element. // Has not been tested enough to be sure it works as expected. $focused = $(lastFocusedElement); } catch (error3) { warnToConsole("Could not use lastFocusedElement ", lastFocusedElement, error3); } } } } return $focused; } </code></pre> <h2>Focus listeners</h2> <pre><code>// Keep a reference to the last focused element, use as a last resort. var lastFocusedElement = null; function focusInElement(event) { lastFocusedElement = event.target; } function focusOutElement(event) { lastFocusedElement = null; } // Start listeners. $(function() { // Start listeners that keep track of the last focused element. $(document).on("focusin", focusInElement); $(document).on("focusout", focusOutElement); }); </code></pre> <p>I don't like this solution very much, as it is far from as clean as just a one-line <code>$(':focus')</code>. Other answers are welcome!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload