11<!DOCTYPE html>
22< html >
3- < body >
4- < div id ="window-label "> </ div >
5- < div id ="container "> </ div >
6- < div id ="response "> </ div >
73
8- < script >
9- var WebviewWindow = window . __TAURI__ . window . WebviewWindow
10- var thisTauriWindow = window . __TAURI__ . window . getCurrent ( )
11- var windowLabel = thisTauriWindow . label
12- var windowLabelContainer = document . getElementById ( 'window-label' )
13- windowLabelContainer . innerHTML = 'This is the ' + windowLabel + ' window.'
4+ < head >
5+ < style >
6+ # response {
7+ white-space : pre-wrap;
8+ }
9+ </ style >
10+ </ head >
1411
15- var container = document . getElementById ( 'container' )
12+ < body >
13+ < div id ="window-label "> </ div >
14+ < div id ="container "> </ div >
15+ < div id ="response "> </ div >
1616
17- function createWindowMessageBtn ( label ) {
18- var tauriWindow = WebviewWindow . getByLabel ( label )
19- var button = document . createElement ( 'button' )
20- button . innerHTML = 'Send message to ' + label
21- button . addEventListener ( 'click' , function ( ) {
22- tauriWindow . emit ( 'clicked' , 'message from ' + windowLabel )
23- } )
24- container . appendChild ( button )
25- }
17+ < script >
18+ var WebviewWindow = window . __TAURI__ . window . WebviewWindow
19+ var thisTauriWindow = window . __TAURI__ . window . getCurrent ( )
20+ var windowLabel = thisTauriWindow . label
21+ var windowLabelContainer = document . getElementById ( 'window-label' )
22+ windowLabelContainer . innerText = 'This is the ' + windowLabel + ' window.'
2623
27- // global listener
28- window . __TAURI__ . event . listen ( 'clicked' , function ( event ) {
29- responseContainer . innerHTML +=
30- 'Got ' + JSON . stringify ( event ) + ' on global listener<br><br>'
31- } )
32- window . __TAURI__ . event . listen ( 'tauri://window-created' , function ( event ) {
33- createWindowMessageBtn ( event . payload . label )
34- } )
24+ var container = document . getElementById ( 'container' )
3525
36- var responseContainer = document . getElementById ( 'response' )
37- // listener tied to this window
38- thisTauriWindow . listen ( 'clicked' , function ( event ) {
39- responseContainer . innerHTML +=
40- 'Got ' + JSON . stringify ( event ) + ' on window listener<br><br>'
26+ function createWindowMessageBtn ( label ) {
27+ var tauriWindow = WebviewWindow . getByLabel ( label )
28+ var button = document . createElement ( 'button' )
29+ button . innerText = 'Send message to ' + label
30+ button . addEventListener ( 'click' , function ( ) {
31+ tauriWindow . emit ( 'clicked' , 'message from ' + windowLabel )
4132 } )
33+ container . appendChild ( button )
34+ }
4235
43- var createWindowButton = document . createElement ( 'button' )
44- createWindowButton . innerHTML = 'Create window'
45- createWindowButton . addEventListener ( 'click' , function ( ) {
46- var webviewWindow = new WebviewWindow ( Math . random ( ) . toString ( ) )
47- webviewWindow . once ( 'tauri://created' , function ( ) {
48- responseContainer . innerHTML += 'Created new webview'
49- } )
50- webviewWindow . once ( 'tauri://error' , function ( ) {
51- responseContainer . innerHTML += 'Error creating new webview'
52- } )
53- } )
54- container . appendChild ( createWindowButton )
36+ // global listener
37+ window . __TAURI__ . event . listen ( 'clicked' , function ( event ) {
38+ responseContainer . innerHTML +=
39+ 'Got ' + JSON . stringify ( event ) + ' on global listener\n\n'
40+ } )
41+ window . __TAURI__ . event . listen ( 'tauri://window-created' , function ( event ) {
42+ createWindowMessageBtn ( event . payload . label )
43+ } )
5544
56- var globalMessageButton = document . createElement ( 'button' )
57- globalMessageButton . innerHTML = 'Send global message'
58- globalMessageButton . addEventListener ( 'click' , function ( ) {
59- // emit to all windows
60- window . __TAURI__ . event . emit ( 'clicked' , 'message from ' + windowLabel )
45+ var responseContainer = document . getElementById ( 'response' )
46+ // listener tied to this window
47+ thisTauriWindow . listen ( 'clicked' , function ( event ) {
48+ responseContainer . innerText +=
49+ 'Got ' + JSON . stringify ( event ) + ' on window listener\n\n'
50+ } )
51+
52+ var createWindowButton = document . createElement ( 'button' )
53+ createWindowButton . innerHTML = 'Create window'
54+ createWindowButton . addEventListener ( 'click' , function ( ) {
55+ var webviewWindow = new WebviewWindow ( Math . random ( ) . toString ( ) )
56+ webviewWindow . once ( 'tauri://created' , function ( ) {
57+ responseContainer . innerHTML += 'Created new webview'
58+ } )
59+ webviewWindow . once ( 'tauri://error' , function ( ) {
60+ responseContainer . innerHTML += 'Error creating new webview'
6161 } )
62- container . appendChild ( globalMessageButton )
62+ } )
63+ container . appendChild ( createWindowButton )
6364
64- var allWindows = window . __TAURI__ . window . getAll ( )
65- for ( var index in allWindows ) {
66- var label = allWindows [ index ] . label
67- if ( label === windowLabel ) {
68- continue
69- }
70- createWindowMessageBtn ( label )
65+ var globalMessageButton = document . createElement ( 'button' )
66+ globalMessageButton . innerHTML = 'Send global message'
67+ globalMessageButton . addEventListener ( 'click' , function ( ) {
68+ // emit to all windows
69+ window . __TAURI__ . event . emit ( 'clicked' , 'message from ' + windowLabel )
70+ } )
71+ container . appendChild ( globalMessageButton )
72+
73+ var allWindows = window . __TAURI__ . window . getAll ( )
74+ for ( var index in allWindows ) {
75+ var label = allWindows [ index ] . label
76+ if ( label === windowLabel ) {
77+ continue
7178 }
72- </ script >
73- </ body >
74- </ html >
79+ createWindowMessageBtn ( label )
80+ }
81+ </ script >
82+ </ body >
83+
84+ </ html >
0 commit comments