Selaa lähdekoodia

feat(examples): add window creation on navigation example (#1692)

Lucas Fernandes Nogueira 4 vuotta sitten
vanhempi
sitoutus
53f842656b

+ 1 - 0
examples/navigation/public/index.html

@@ -15,6 +15,7 @@
     <option value="nested/index.html">nested/index.html</option>
     <option value="nested/secondary.html">nested/secondary.html</option>
   </select>
+  <button id="open-window">New window</button>
   <button id="go">Go</button>
   <a id="link" href="secondary.html">Go</a>
   <script src="index.js"></script>

+ 8 - 0
examples/navigation/public/index.js

@@ -1,3 +1,5 @@
+const WebviewWindow = window.__TAURI__.window.WebviewWindow
+
 const routeSelect = document.querySelector('#route')
 const link = document.querySelector('#link')
 
@@ -8,3 +10,9 @@ routeSelect.addEventListener('change', (event) => {
 document.querySelector('#go').addEventListener('click', () => {
   window.location.href = (window.location.origin + '/' + routeSelect.value)
 })
+
+document.querySelector('#open-window').addEventListener('click', () => {
+  new WebviewWindow(Math.random().toString(), {
+    url: routeSelect.value
+  })
+})

+ 2 - 1
examples/navigation/src-tauri/tauri.conf.json

@@ -3,7 +3,8 @@
     "distDir": "../public",
     "devPath": "../public",
     "beforeDevCommand": "",
-    "beforeBuildCommand": ""
+    "beforeBuildCommand": "",
+    "withGlobalTauri": true
   },
   "tauri": {
     "bundle": {