how to paste something into an input from clipboard without using document.ExecCommand('paste') ?

how to paste something into an input from clipboard without using document.ExecCommand('paste') since it is considered obsolete by MDN ?
6 Replies
i_lost_to_loba_kreygasm
I see the read method from clipboard and changing input value but I really have to use paste to trigger paste event the only way I see is manually triggering Ctrl + V with dispatch event but I am wondering if anybody knows a better way
Jochem
Jochem2y ago
I honestly really really hope there's no way to read clipboard contents from a website, as that would be a massive security concern also, I'm pretty sure that dispatching a ctrl+v event will only have the browser register as if ctrl+v has been pressed, but it won't actually paste anything because the pasting is done by the OS, which doesn't care about what the browser is doing so unless you're writing an extension, in which case you'll have to be more specific about which browser you're writing it for, I don't think there is a way and I don't think there should be a way
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Jochem
Jochem2y ago
isn't that all for handling content after it's been pasted though? the first one listens to the paste event, which only fires when the user actively pastes something The second one requires the user recently using the page and granting permission to access the clipboard using the permissions API, which doesn't seem to have a way to request permissions built into the webpage side of any browser atm The third one doesn't make a ton of sense to me... It's overwriting the val function on the jquery prototype and then calling that function on #inputField? @TAHIDUR did you copy paste this from ChatGPT or something?
b1mind
b1mind2y ago
I'm at a loss for the use case of this period? If the user pastes into an input it should be the value they pasted. If you are trying to put something there why not just assign the input.value? I agree with Jochems points too. Seems very anti UX.
Jochem
Jochem2y ago
hm, so firefox just straight up doesn't support .read or .readText on navigator.clipboard, and chrome asks for permission from the user first, that's good at least chrome also requires the document to have focus, and the user to have recently interacted with it, for the read to work
Want results from more Discord servers?
Add your server