I'm trying to build an extension. The first event runs outside of any browser and is triggered by a hotkey. That hotkey triggers a prompt and the result of that prompt is used query a webpage.
By default I'd like the prompt to be populated form the user's clipboard. I have enabled all the appropriate permissions. Is there any way to "focus" on the input box in the prompt window such that "document.execCommand('paste');" will work?
Is there a way to modify the third line of the following javascript to achieve the desired result?
JavaScript
document.getElementById("myButton").addEventListener("click", function(){
var result = prompt("enter value");
document.execCommand('paste');
alert(result);
});
html
<input type="button" value="clickme" id="myButton">
If you're using document.execCommand
, not to mention prompt
, that means you're running in a browser environment. So your best bet is to implement a simple overlay + modal dialog in the browser, paste the clipboard contents in an input there, and proceed.
And sadly, you can't "focus" on the clipboard: document.execCommand
already uses the clipboard. The input in a prompt isn't part of the DOM, so it won't respond to javascript manipulation. :(
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.