Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5837885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:24:33+00:00 2026-05-22T11:24:33+00:00

Gmail handles its drag-and-drop file attachment uploading in a few clever ways: 1) Dragging

  • 0

Gmail handles its drag-and-drop file attachment uploading in a few clever ways:

1) Dragging a file into the browser causes the dropzone to appear. The cursor displays feedback indicating whether you are in the dropzone or not (in windows, a red crossthrough circle is used if outside the dropzone). If you drop inside the window but outside of the dropzone, the drop is intercepted such that the browser’s default behavior is prevented (usually navigating away to display the dragged file).

The most obvious way to attempt this is to set dragover handler on the BODY to make the dropzone appear and preventDefault, but what about the cursor change? Is there some way to use dataTransfer.effectAllowed=’none’?

2) Dragging text from one part of the window into another part does not trigger the drag-and-drop handling (ie- the dropzone does not appear)–and the preventDefault mentioned in #1 does not kick in.

If I capture the dragover event on the BODY (from #1), then intra-window text dragging is prevented. How do they accomplish both of these at the same time? It seems like this is more complex than it at first might appear.

UPDATE:

I learned two related things while trying to completely address this:

1) It appears that IE will not even trigger the drop event handler if dropEffect=’none’… so I decided to only set it to none if e.dataTransfer.types exists (which it does in Chrome & FF, but not in IE). The downside is that the cursor doesn’t have the red crossthrough, but at least I can intercept the drop to prevent a navaway. Your best guess for determining whether it was a file drop in IE is if e.dataTransfer.getData(‘Text’)==null. (In my case, I wanted to be able to receive drops of either files or text, so this is how I can tell the difference in IE.)

2) It was non-obvious how Gmail hides the dropzone when you leave the browser. If you use a pure dragleave event on the page, then dragging into any child will trigger the dragleave handler even though you didn’t really leave the page. I then noticed that there’s a delay in Gmail before the dropzone disappears, so I would guess they use a timer to hide the dropzone (which gets reset on something like dragover). But I’ve come up with an alternate solution that appears to work so far:

function areXYInside(e){  
        var w=e.target.offsetWidth;
        var h=e.target.offsetHeight;
        var x=e.offsetX;
        var y=e.offsetY;
        return !(x<0 || x>=w || y<0 || y>=h);
}

And then:

$("#page").bind('dragleave', function(e){
        if(this!=e.target) return false;
        if(!areXYInside(e)){
                hideBox();
        }                 
        return false;
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:24:33+00:00Added an answer on May 22, 2026 at 11:24 am

    I believe they are setting dataTransfer.effectAllowedon dragover, depending on the dataTransfer.types attribute.

    EDIT: I was wrong the first time, here are the actual values for types(in Chrome at least):
    – dragging text ["text/html","text","text/plain"]
    – dragging a file ["Files"]

    Here is a short jsFiddle example to play around with.

    You can check more info about drag and drop at w3c or mdc.

    EDIT: I managed to implement the exact behavior on Chrome and FF (see here)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to reproduce the way GMail handles html5 drag/drop attachments -- where as
All Gmail users should have already noticed that file upload progress bar has been
When I look at gmail on my mobile web browser the password textbox hashes
I'm wondering if anyone knows how exactly Gmail, Hotmail, Facebook etc handles following scenario.
I am interested in the way that gmail handles fragments and their transitions. I'm
I want to make a interactive uploading option like Facebook and gmail have where
Does Gmail support RFC 821? I know it is using ESMTP. Based on understanding
concerning Gmail labels - what are they technically speaking. I mean through imap connection
Is there any Gmail sdk for android, just like facebook sdk. I don't want
I've noticed that Gmail, Hotmail, Yahoo, and Ebay all have their login boxes on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.