-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.go
56 lines (38 loc) · 1.15 KB
/
window.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//go:build js && wasm
package js
import (
"fmt"
"syscall/js"
)
type IntervalID = js.Value
// -----------------------------------------------------------------------------
func Window() js.Value {
return global
}
// -----------------------------------------------------------------------------
func Alert(a ...any) {
global.Call("alert", fmt.Sprint(a...))
}
// -----------------------------------------------------------------------------
func Alertf(format string, a ...any) {
global.Call("alert", fmt.Sprintf(format, a...))
}
// -----------------------------------------------------------------------------
func Redirect(newURL string) {
global.Get("location").Set("href", newURL)
}
// -----------------------------------------------------------------------------
func SetInterval(fn js.Func, ms int, args ...any) IntervalID {
if ms < 4 {
ms = 0
}
newArgs := append([]any{fn, ms}, args...)
return global.Call("setInterval", newArgs...)
}
// -----------------------------------------------------------------------------
func ClearInterval(id IntervalID) {
global.Call("clearInterval", id)
}
func Reload() {
global.Get("location").Call("reload")
}