0

I have a text input.

I drag the URL from a browser window into the text field. (Click hold on the URL bar, drag, let go of click in the text field).

Which event fires in this case? Listening on paste ain't doing it. Is this the same for every browser?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
hvgotcodes
  • 118,147
  • 33
  • 203
  • 236

2 Answers2

1

paste is the event that should work - what browser ?

http://www.quirksmode.org/dom/events/cutcopypaste.html

Example : http://jsfiddle.net/VdUqx/1/ <- works for me in Chrome

Manse
  • 37,765
  • 10
  • 83
  • 108
  • yeah paste, and mouseup fire. I was setting up my listener incorrectly. Btw, your example is not working for me... – hvgotcodes Dec 06 '11 at 14:24
  • @hvgotcodes updated the way the event is attached - should work in all browsers now ... – Manse Dec 06 '11 at 14:28
  • hmm still not working. I'm running the code in chrome, but can drag from the URL bar of any browser/window – hvgotcodes Dec 06 '11 at 14:29
  • @hvgotcodes Yes your right - not working for drag / drop - but working for paste ... not sure there is an event (other than mouseup) that will capture this event ... – Manse Dec 06 '11 at 14:33
  • @hvgotcodes here is an alternative way of doing it http://stackoverflow.com/questions/1021171/catch-image-dragged-into-a-text-field-in-javascript you could check for the `http` at the start ? – Manse Dec 06 '11 at 14:34
1

You will get an HTML5 input event in all browsers except IE<9, in which you can use the propertychange event instead.

Tim Down
  • 318,141
  • 75
  • 454
  • 536
  • i am using evt.target.value to get the value of the input -- do you know if that will work cross browsers? – hvgotcodes Dec 12 '11 at 18:41
  • @hvgotcodes: You'll need `window.event.srcElement.value` instead in IE <= 8, and the `propertychange` event doesn't bubble, so you'll need to attach your listener directly to the input you're interested in. – Tim Down Dec 12 '11 at 21:40