Disable the drag-and-drop for textDetect file type on dragenter cross browser solutionGetting the filename during the dragenter eventjQuery get specific option tag textDisable Drag and Drop on HTML elements?Disable/enable an input with jQuery?Get selected text from a drop-down list (select box) using jQueryDisable same origin policy in ChromeHow do I prevent drag on a child, but allow drag on the parent?How does Facebook disable the browser's integrated Developer Tools?HTML5 drag and drop element over div with Hammer.js drag eventsjQuery Drag & Drop - only allow drags from outside the browserdrag to browser and detect mime of file being dropped

What's the idiomatic (or best) way to trim surrounding whitespace from a string?

Disk usage confusion: 10G missing on Linux home partition on SSD

How soon after takeoff can you recline your airplane seat?

How to remove system locales

A quine of sorts

How useful would a hydroelectric power plant be in the post-apocalypse world?

How much of a mortgage should I take on to maximize my 5 year financial plan?

Rear derailleur got caught in the spokes, what could be a root cause

Why did the Apple IIe make a hideous noise if you inserted the disk upside down?

Any Tips On Writing Extended Recollection In A Novel

Solve limit without using L'Hopital (first year problem for first year solution, not graduate level)

A* pathfinding algorithm too slow

How does the 'five minute adventuring day' affect class balance?

Is it OK to say "The situation is pregnant with a crisis"?

Why is my 401k manager recommending me to save more?

Did NASA distinguish between the space shuttle cockpit and flight deck?

Chandra exiles a card, I play it, it gets exiled again

Basis and cardinality

How to track mail undetectably?

What was the point of separating stdout and stderr?

Why do movie directors use brown tint on Mexico cities?

Can I deep fry food in butter instead of vegetable oil?

Why didn't Avengers simply jump 5 years back?

Advantages of using bra-ket notation



Disable the drag-and-drop for text


Detect file type on dragenter cross browser solutionGetting the filename during the dragenter eventjQuery get specific option tag textDisable Drag and Drop on HTML elements?Disable/enable an input with jQuery?Get selected text from a drop-down list (select box) using jQueryDisable same origin policy in ChromeHow do I prevent drag on a child, but allow drag on the parent?How does Facebook disable the browser's integrated Developer Tools?HTML5 drag and drop element over div with Hammer.js drag eventsjQuery Drag & Drop - only allow drags from outside the browserdrag to browser and detect mime of file being dropped













0















I am developing a drag-and-drop system for image files and I have noticed that the dragenter event is also executed on the selected text drag.



$(document).on("dragenter", "#element", function(event)
event.preventDefault();

// Check if we are dragging text

if(is_text) // <- HERE
console.log("dragging text!");
else
console.log("dragging file!");

);


I want to detect that the dragged object is not text, so the previous console.log would not run if it were.



UPDATE AND SOLUTION:



var dragging_text = false;

$(window).on("dragstart", function(event)
dragging_text = true;
console.log("dragstart");
);

$(document).on("dragenter", "#element", function(event)
event.preventDefault();

if(dragging_text)
console.log("NO, dragging text!");
else
console.log("OK, dragging file!");

);









share|improve this question
























  • just not understand what you mean by text, you can not drag and drop text !

    – mooga
    Mar 25 at 16:39











  • @mooga The dragenter event fires when you select and drag text. I want to avoid it.

    – Smark
    Mar 25 at 16:41















0















I am developing a drag-and-drop system for image files and I have noticed that the dragenter event is also executed on the selected text drag.



$(document).on("dragenter", "#element", function(event)
event.preventDefault();

// Check if we are dragging text

if(is_text) // <- HERE
console.log("dragging text!");
else
console.log("dragging file!");

);


I want to detect that the dragged object is not text, so the previous console.log would not run if it were.



UPDATE AND SOLUTION:



var dragging_text = false;

$(window).on("dragstart", function(event)
dragging_text = true;
console.log("dragstart");
);

$(document).on("dragenter", "#element", function(event)
event.preventDefault();

if(dragging_text)
console.log("NO, dragging text!");
else
console.log("OK, dragging file!");

);









share|improve this question
























  • just not understand what you mean by text, you can not drag and drop text !

    – mooga
    Mar 25 at 16:39











  • @mooga The dragenter event fires when you select and drag text. I want to avoid it.

    – Smark
    Mar 25 at 16:41













0












0








0








I am developing a drag-and-drop system for image files and I have noticed that the dragenter event is also executed on the selected text drag.



$(document).on("dragenter", "#element", function(event)
event.preventDefault();

// Check if we are dragging text

if(is_text) // <- HERE
console.log("dragging text!");
else
console.log("dragging file!");

);


I want to detect that the dragged object is not text, so the previous console.log would not run if it were.



UPDATE AND SOLUTION:



var dragging_text = false;

$(window).on("dragstart", function(event)
dragging_text = true;
console.log("dragstart");
);

$(document).on("dragenter", "#element", function(event)
event.preventDefault();

if(dragging_text)
console.log("NO, dragging text!");
else
console.log("OK, dragging file!");

);









share|improve this question
















I am developing a drag-and-drop system for image files and I have noticed that the dragenter event is also executed on the selected text drag.



$(document).on("dragenter", "#element", function(event)
event.preventDefault();

// Check if we are dragging text

if(is_text) // <- HERE
console.log("dragging text!");
else
console.log("dragging file!");

);


I want to detect that the dragged object is not text, so the previous console.log would not run if it were.



UPDATE AND SOLUTION:



var dragging_text = false;

$(window).on("dragstart", function(event)
dragging_text = true;
console.log("dragstart");
);

$(document).on("dragenter", "#element", function(event)
event.preventDefault();

if(dragging_text)
console.log("NO, dragging text!");
else
console.log("OK, dragging file!");

);






javascript jquery drag-and-drop






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 10:17







Smark

















asked Mar 25 at 16:34









SmarkSmark

598 bronze badges




598 bronze badges












  • just not understand what you mean by text, you can not drag and drop text !

    – mooga
    Mar 25 at 16:39











  • @mooga The dragenter event fires when you select and drag text. I want to avoid it.

    – Smark
    Mar 25 at 16:41

















  • just not understand what you mean by text, you can not drag and drop text !

    – mooga
    Mar 25 at 16:39











  • @mooga The dragenter event fires when you select and drag text. I want to avoid it.

    – Smark
    Mar 25 at 16:41
















just not understand what you mean by text, you can not drag and drop text !

– mooga
Mar 25 at 16:39





just not understand what you mean by text, you can not drag and drop text !

– mooga
Mar 25 at 16:39













@mooga The dragenter event fires when you select and drag text. I want to avoid it.

– Smark
Mar 25 at 16:41





@mooga The dragenter event fires when you select and drag text. I want to avoid it.

– Smark
Mar 25 at 16:41










2 Answers
2






active

oldest

votes


















0














This will help you know:



 var dragging_text = false;

$(window).on("dragstart", function(event)
dragging_text = true;
console.log("dragstart");
);

$(document).on("dragenter", "#element", function(event)
event.preventDefault();

if(dragging_text)
console.log("NO, dragging text!");
else
console.log("OK, dragging file!");

dragging_text = false;
);





share|improve this answer

























  • I've researched about dragstart and it seems to work fine. I update the post with my solution.

    – Smark
    Mar 26 at 10:18











  • Don't forget to add 'dragging_text = false;' in the dragenter() event, tell me if it works.

    – Richard Socker
    Mar 26 at 10:33











  • Thanks, I forgot to include dragging_text = false; in dragenter event. I've done tests and it seems to work fine.

    – Smark
    Mar 26 at 10:44


















0














You need to check DataTransfer



$(document).on("dragenter", "#element", function(event) 
if(event.dataTransfer.files.length > 0) // <- HERE
console.log("dragenter");
else
event.preventDefault();

);





share|improve this answer

























  • I have updated the question to see if it is better understood now.

    – Smark
    Mar 25 at 16:48











  • have used if(event.dataTransfer.files.length > 0){ ?

    – mooga
    Mar 25 at 16:52












  • Yes, but with that line it does not let me drag files.

    – Smark
    Mar 25 at 16:56











  • because you block it anyway, i have changed the code , try it

    – mooga
    Mar 25 at 17:00











  • dataTransfer works in the dragenter event? I have documented and I have seen that it does not work.

    – Smark
    Mar 25 at 17:05













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55342477%2fdisable-the-drag-and-drop-for-text%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














This will help you know:



 var dragging_text = false;

$(window).on("dragstart", function(event)
dragging_text = true;
console.log("dragstart");
);

$(document).on("dragenter", "#element", function(event)
event.preventDefault();

if(dragging_text)
console.log("NO, dragging text!");
else
console.log("OK, dragging file!");

dragging_text = false;
);





share|improve this answer

























  • I've researched about dragstart and it seems to work fine. I update the post with my solution.

    – Smark
    Mar 26 at 10:18











  • Don't forget to add 'dragging_text = false;' in the dragenter() event, tell me if it works.

    – Richard Socker
    Mar 26 at 10:33











  • Thanks, I forgot to include dragging_text = false; in dragenter event. I've done tests and it seems to work fine.

    – Smark
    Mar 26 at 10:44















0














This will help you know:



 var dragging_text = false;

$(window).on("dragstart", function(event)
dragging_text = true;
console.log("dragstart");
);

$(document).on("dragenter", "#element", function(event)
event.preventDefault();

if(dragging_text)
console.log("NO, dragging text!");
else
console.log("OK, dragging file!");

dragging_text = false;
);





share|improve this answer

























  • I've researched about dragstart and it seems to work fine. I update the post with my solution.

    – Smark
    Mar 26 at 10:18











  • Don't forget to add 'dragging_text = false;' in the dragenter() event, tell me if it works.

    – Richard Socker
    Mar 26 at 10:33











  • Thanks, I forgot to include dragging_text = false; in dragenter event. I've done tests and it seems to work fine.

    – Smark
    Mar 26 at 10:44













0












0








0







This will help you know:



 var dragging_text = false;

$(window).on("dragstart", function(event)
dragging_text = true;
console.log("dragstart");
);

$(document).on("dragenter", "#element", function(event)
event.preventDefault();

if(dragging_text)
console.log("NO, dragging text!");
else
console.log("OK, dragging file!");

dragging_text = false;
);





share|improve this answer















This will help you know:



 var dragging_text = false;

$(window).on("dragstart", function(event)
dragging_text = true;
console.log("dragstart");
);

$(document).on("dragenter", "#element", function(event)
event.preventDefault();

if(dragging_text)
console.log("NO, dragging text!");
else
console.log("OK, dragging file!");

dragging_text = false;
);






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 26 at 10:32

























answered Mar 26 at 9:43









Richard SockerRichard Socker

24110 bronze badges




24110 bronze badges












  • I've researched about dragstart and it seems to work fine. I update the post with my solution.

    – Smark
    Mar 26 at 10:18











  • Don't forget to add 'dragging_text = false;' in the dragenter() event, tell me if it works.

    – Richard Socker
    Mar 26 at 10:33











  • Thanks, I forgot to include dragging_text = false; in dragenter event. I've done tests and it seems to work fine.

    – Smark
    Mar 26 at 10:44

















  • I've researched about dragstart and it seems to work fine. I update the post with my solution.

    – Smark
    Mar 26 at 10:18











  • Don't forget to add 'dragging_text = false;' in the dragenter() event, tell me if it works.

    – Richard Socker
    Mar 26 at 10:33











  • Thanks, I forgot to include dragging_text = false; in dragenter event. I've done tests and it seems to work fine.

    – Smark
    Mar 26 at 10:44
















I've researched about dragstart and it seems to work fine. I update the post with my solution.

– Smark
Mar 26 at 10:18





I've researched about dragstart and it seems to work fine. I update the post with my solution.

– Smark
Mar 26 at 10:18













Don't forget to add 'dragging_text = false;' in the dragenter() event, tell me if it works.

– Richard Socker
Mar 26 at 10:33





Don't forget to add 'dragging_text = false;' in the dragenter() event, tell me if it works.

– Richard Socker
Mar 26 at 10:33













Thanks, I forgot to include dragging_text = false; in dragenter event. I've done tests and it seems to work fine.

– Smark
Mar 26 at 10:44





Thanks, I forgot to include dragging_text = false; in dragenter event. I've done tests and it seems to work fine.

– Smark
Mar 26 at 10:44











0














You need to check DataTransfer



$(document).on("dragenter", "#element", function(event) 
if(event.dataTransfer.files.length > 0) // <- HERE
console.log("dragenter");
else
event.preventDefault();

);





share|improve this answer

























  • I have updated the question to see if it is better understood now.

    – Smark
    Mar 25 at 16:48











  • have used if(event.dataTransfer.files.length > 0){ ?

    – mooga
    Mar 25 at 16:52












  • Yes, but with that line it does not let me drag files.

    – Smark
    Mar 25 at 16:56











  • because you block it anyway, i have changed the code , try it

    – mooga
    Mar 25 at 17:00











  • dataTransfer works in the dragenter event? I have documented and I have seen that it does not work.

    – Smark
    Mar 25 at 17:05















0














You need to check DataTransfer



$(document).on("dragenter", "#element", function(event) 
if(event.dataTransfer.files.length > 0) // <- HERE
console.log("dragenter");
else
event.preventDefault();

);





share|improve this answer

























  • I have updated the question to see if it is better understood now.

    – Smark
    Mar 25 at 16:48











  • have used if(event.dataTransfer.files.length > 0){ ?

    – mooga
    Mar 25 at 16:52












  • Yes, but with that line it does not let me drag files.

    – Smark
    Mar 25 at 16:56











  • because you block it anyway, i have changed the code , try it

    – mooga
    Mar 25 at 17:00











  • dataTransfer works in the dragenter event? I have documented and I have seen that it does not work.

    – Smark
    Mar 25 at 17:05













0












0








0







You need to check DataTransfer



$(document).on("dragenter", "#element", function(event) 
if(event.dataTransfer.files.length > 0) // <- HERE
console.log("dragenter");
else
event.preventDefault();

);





share|improve this answer















You need to check DataTransfer



$(document).on("dragenter", "#element", function(event) 
if(event.dataTransfer.files.length > 0) // <- HERE
console.log("dragenter");
else
event.preventDefault();

);






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 25 at 16:59

























answered Mar 25 at 16:41









moogamooga

1,5604 gold badges12 silver badges25 bronze badges




1,5604 gold badges12 silver badges25 bronze badges












  • I have updated the question to see if it is better understood now.

    – Smark
    Mar 25 at 16:48











  • have used if(event.dataTransfer.files.length > 0){ ?

    – mooga
    Mar 25 at 16:52












  • Yes, but with that line it does not let me drag files.

    – Smark
    Mar 25 at 16:56











  • because you block it anyway, i have changed the code , try it

    – mooga
    Mar 25 at 17:00











  • dataTransfer works in the dragenter event? I have documented and I have seen that it does not work.

    – Smark
    Mar 25 at 17:05

















  • I have updated the question to see if it is better understood now.

    – Smark
    Mar 25 at 16:48











  • have used if(event.dataTransfer.files.length > 0){ ?

    – mooga
    Mar 25 at 16:52












  • Yes, but with that line it does not let me drag files.

    – Smark
    Mar 25 at 16:56











  • because you block it anyway, i have changed the code , try it

    – mooga
    Mar 25 at 17:00











  • dataTransfer works in the dragenter event? I have documented and I have seen that it does not work.

    – Smark
    Mar 25 at 17:05
















I have updated the question to see if it is better understood now.

– Smark
Mar 25 at 16:48





I have updated the question to see if it is better understood now.

– Smark
Mar 25 at 16:48













have used if(event.dataTransfer.files.length > 0){ ?

– mooga
Mar 25 at 16:52






have used if(event.dataTransfer.files.length > 0){ ?

– mooga
Mar 25 at 16:52














Yes, but with that line it does not let me drag files.

– Smark
Mar 25 at 16:56





Yes, but with that line it does not let me drag files.

– Smark
Mar 25 at 16:56













because you block it anyway, i have changed the code , try it

– mooga
Mar 25 at 17:00





because you block it anyway, i have changed the code , try it

– mooga
Mar 25 at 17:00













dataTransfer works in the dragenter event? I have documented and I have seen that it does not work.

– Smark
Mar 25 at 17:05





dataTransfer works in the dragenter event? I have documented and I have seen that it does not work.

– Smark
Mar 25 at 17:05

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55342477%2fdisable-the-drag-and-drop-for-text%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript