2

I want a Javascript only solution to invoke the HTML5 color picker

<input type="color" />

Apparently you can not simulate a click on an input element because of security issues

In JavaScript can I make a "click" event fire programmatically for a file input element?

If anyone has a work around for this situation it would be really useful in my situation.


Note: A Javascript only solution means I can trigger it from the Javascript console without interacting with any HTML elements.

Community
  • 1
  • 1
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
  • Of course you can simulate a click or change event on an input, the linked question pertains to inputs with the type "file", where triggering a file upload would be a security risk, not in general ? – adeneo May 28 '13 at 21:48
  • 2
    @adeneo seems not to work for input type color in chrome too (not tested other browsers): http://jsfiddle.net/TNmR9/ – A. Wolff May 28 '13 at 21:49
  • @roasted - it probably doesn't, haven't tested it, but as that also opens an external window and relies on built in browser stuff, you probably can't trigger it ? – adeneo May 28 '13 at 21:53
  • How exactly do you want this event to be triggered? I mean, has your user to click somewhere else or you want to open it on completly different event (e.g onload...)? – A. Wolff May 28 '13 at 21:58
  • I need it to be triggered as a function, as this is a hidden webview within a native mobile app. – Philip Kirkbride May 28 '13 at 22:01
  • 1
    I don't think you can, it's not that it's really a security risk, it's just seems like browsers haven't implemented a way to do this yet ? – adeneo May 28 '13 at 22:10
  • I realize that it seems impossible at this point in time, but I guess this question is for anyone who can find a hack around, or to post an answer when if it becomes possible in the future. I had to remove the functionality I was planning because I assume this won't be answered anytime soon. – Philip Kirkbride May 28 '13 at 22:15
  • 1
    Why would this get downvoted. It's a very good question. – SomeShinyObject May 28 '13 at 23:46

0 Answers0