Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to detect the dragleave event in Firefox when dragging outside the window
    primarykey
    data
    text
    <p>Firefox doesn't properly trigger the dragleave event when dragging outside of the window:</p> <p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=665704" rel="nofollow noreferrer">https://bugzilla.mozilla.org/show_bug.cgi?id=665704</a></p> <p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=656164" rel="nofollow noreferrer">https://bugzilla.mozilla.org/show_bug.cgi?id=656164</a></p> <p>I'm trying to develop a workaround for this (which I know is possible because Gmail is doing it), but the only thing I can come up with seems really hackish.</p> <p>One way of knowing when dragging outside the window has occurred it to wait for the <code>dragover</code> event to stop firing (because <code>dragover</code> fires constantly during a drag and drop operation). Here's how I'm doing that:</p> <pre><code>var timeout; function dragleaveFunctionality() { // do stuff } function firefoxTimeoutHack() { clearTimeout(timeout); timeout = setTimeout(dragleaveFunctionality, 200); } $(document).on('dragover', firefoxTimeoutHack); </code></pre> <p>This code is essentially creating and clearing a timeout over and over again. The 200 millisecond timeout will not be reached unless the <code>dragover</code> event stops firing.</p> <p>While this works, I don't like the idea of using a timeout for this purpose. It feels wrong. It also means there's a slight lag before the "dropzone" styling goes away.</p> <p>The other idea I had was to detect when the mouse leaves the window, but the normal ways of doing that don't seem to work during drag and drop operations.</p> <p>Does anyone out there have a better way of doing this?</p> <p><strong>UPDATE:</strong></p> <p>Here's the code I am using:</p> <pre><code>&lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Drag and Drop Issue&lt;/title&gt; &lt;script src="http://code.jquery.com/jquery.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; Open up the console and look at what number is reporting when dragging files in and out of the window. The number should always be 0 when leaving the window, but in Firefox it's not. &lt;script type="text/javascript"&gt; $(function() { var counter = 0; $(document).on('dragenter', function(e) { counter += 1; console.log(counter, e.target); }); $(document).on('dragleave', function(e) { counter -= 1; console.log(counter, e.target); }); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    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