How do you register an event for a URL dropped in an input field

I have a web form with an input text box for a url. When I drag the URL from the browser (I use firefox, but I would like it to work in others, if possible) the address bar in the input field, it inserts the url text into any existing text. I want the url to rewrite any existing text.

I think I can capture some kind of event and lighten any existing text before adding the discarded text.

If you can customize using jQuery, which is good, otherwise in plain javascript.

Edit

It works:

$("#myinput").bind("drop", function(e) { e.currentTarget.value = ""; return true; }); 

I'm not sure that browsers support this event, but if it is the most modern, then everything should be fine.

+4
source share
2 answers

If you use targeting like firefox 3.5+, safari or chrome, the ondrop event should work. You can use the form provided by Dr.Molle, or you can install the ondrop handler using javascript.

 //for ie must use this syntax or the html version document.getElementById('myInput').ondrop = function(e){ //doesn't have to be jquery here //using window.location because I can't test e.dataTransfer.getData('Text') right now $(this).val(window.location); } 
0
source

There is an ondrop-event event:

 <input ondrop="this.value=''"> 
0
source

All Articles