Chrome provides a copy(myCopyObj)
to copy an object. Do we have anything similar in terms of pasting an object or getting the contents from the clipboard?
Asked
Active
Viewed 2,515 times
4
Vikramjit Roy
- 396
- 3
- 7
-
Use window.getSelection – Sumesh TG Jul 06 '18 at 06:10
-
1Check https://developers.google.com/web/updates/2018/03/clipboardapi – apokryfos Jul 06 '18 at 06:38
-
1I am talking about chrome console NOT javascript or DOM for clipboard events. – Vikramjit Roy Jul 11 '18 at 12:40
2 Answers
1
Press enter after copy(myCopyObj)
then try to Paste(ctrl+V)
. This will solve your purpose.
Anurag Tomar
- 36
- 5
-
I think the question is about accessing the clipboard content directly as a programmatic expression, like how `copy` takes an expression and sets the clipboard. You can use `ctrl+v` to paste the value into a string literal. But this is inconvenient if the clipboard is a string that contains newlines, which will need to be escaped from the string literal, or if it is an image or something else. – Ben J Sep 01 '20 at 11:38
1
"Getting the contents from clipboard"
Execute the following on devtools side and within 3 seconds focus on the window (by clicking somewhere, or just hitting <tab>
).
setTimeout(async()=>console.log(await window.navigator.clipboard.readText()), 3000)
This will just print the clipboard content. You can replace console.log with code that actually uses the clipboard content.
Jannis Ioannou
- 572
- 1
- 5
- 9