#Open new window from JS

2 messages · Page 1 of 1 (latest)

teal pier
#

I'm using this to open new windows in JS. Something similar worked in Tauri v1. Is this correct? I'm getting the error message that's it's an unstable API.

const w = await Window.getByLabel(ROUTE_SETTINGS);
          if (w) return w.setFocus();

          const window = new Window(ROUTE_SETTINGS, {
            hiddenTitle: true,
            width: 400,
            height: 500,
            focus: true,
            maximizable: false,
            resizable: false,
            center: true,
            titleBarStyle: "overlay",
          });
          const webview = new Webview(window, ROUTE_SETTINGS, {
            url: ROUTE_SETTINGS,
            x: 0,
            y: 0,
            height: 500,
            width: 400,
            // transparent: true,
          });

          webview.once("tauri://created", () => console.log("created"));
          webview.once("tauri://error", (e) => console.log("error", e));
#
          const w = await WebviewWindow.getByLabel(ROUTE_SETTINGS);
          if (w) return w.setFocus();

          const webview = new WebviewWindow(ROUTE_SETTINGS, {
            hiddenTitle: true,
            width: 400,
            height: 500,
            focus: true,
            maximizable: false,
            resizable: false,
            center: true,
            titleBarStyle: "overlay",
            url: ROUTE_SETTINGS,
          });

Works using WebviewWindow
It's just the example at https://tauri.app/reference/javascript/api/namespacewebviewwindow/#example is confusing.

Tauri

The cross-platform app building toolkit