問題描述
我想使用 JavaScript 發出 CtrlS keydown 事件.理想情況下,該解決方案適用于大多數現代瀏覽器(最高 IE 9).
I would like to emit a CtrlS keydown event using JavaScript. Ideally the solution works in most modern browsers (up to IE 9).
我正在編寫測試并且需要測試我的處理程序的鍵綁定.CtrlS 只是一個例子,它可以是任何帶有修飾鍵的鍵綁定.我知道 keyEvent.initKeyboardEvent()
方法,但我無法正確使用它來觸發在按下鍵盤鍵后打印出全鍵盤事件時得到的相同事件.p>
I am writing tests and need to test my handler for key bindings. CtrlS is just an example, it can be any key binding with a modifier key. I know about the keyEvent.initKeyboardEvent()
method but I was not able to use it correctly to trigger the same event I got when printing out the full keyboard event after pressing the key from the keyboard.
推薦答案
我想發出一個 CtrlS keydown 事件
I would like to emit a CtrlS keydown event
你的意思是,為了觸發瀏覽器的另存為"對話框什么的?出于安全原因,這是不可能的.如果是這樣,那將是一個巨大的安全問題——想象一下:每個網站都可以任意觸發瀏覽器功能.
You mean, in order to trigger the browser's "Save as" dialog or something? That's not possible for security reasons. It would be a huge security problem if it were - imagine: every web site could arbitrarily trigger browser functions.
這篇關于以編程方式觸發 Ctrl+S的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!