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