8
Simulate Enter Key Pressed in Go
source link: http://siongui.github.io/2020/07/15/simulate-enter-key-pressed-in-go/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Simulate enter key pressed via Go/ GopherJS, i.e., programmatically fire enter key event in browsers without user intervention.
JavaScript
From [2] we know JavaScript code for firing enter keyevent would be:
const ke = new KeyboardEvent("keyup", {keyCode: 13}); document.body.dispatchEvent(ke);
GopherJS
The above code in Go/GopherJS is as follows:
import ( "github.com/gopherjs/gopherjs/js" ) option := js.Global.Get("Object").New() option.Set("keyCode", 13) ke := js.Global.Get("KeyboardEvent").New("keyup", option) js.Global.Get("document").Get("body").Call("dispatchEvent", ke)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK