javascript - 如何删除在 Electron 中从 index.html 到 contact.html 的转换过程中创建的空白页?

标签 javascript html css node.js electron

当我单击一个链接时,例如在 index.html 中单击外部“contact.html”中的“contact”,加载页面“contact.html”所需的时间很慢。这个利兹在加载第二页时创建一个空白页。 我正在使用 ubuntu 作为操作系统在 raspberry pi 3 上进行开发。

我的问题是如何删除 electron 中从 index.html 到 contact.html 的转换过程中创建的空白页面,有什么建议吗?

最佳答案

你基本上有两个选择:

选项 1: 优化 contact.html 以使用预加载器(内容加载时的等待屏幕)和缓存。

选项 2: 使用 BrowserWindowready-to-show 事件并在显示 contact.html 的同时显示不同的 BrowserWindow > 仍在加载中

选项 2 的代码:

function showExternalPage(url) {
    let externalWindow = new BrowserWindow({
            width: 1280,
            minWidth: 640,
            height: 960,
            minHeight: 480,
            show: false // -> Don't show it, it'll be shown when the content has been loaded (ready-to-show), show the WaitingWindow in the meantime
        }),
        waitingWindow = new BrowserWindow({
            width: 300,
            height: 200,
            transparent: true,
            frame: false,
            alwaysOnTop: true,
            show: false
        });

    externalWindow.loadURL(url);
    waitingWindow.loadURL(url.format({
        pathname: "PATH_TO_WAITING_HTML",
        protocol: 'file:',
        slashes: true
    }));

    // Show the waitingWindow prior to the external window
    waitingWindow.show();

    externalWindow.once('ready-to-show', () => {
        externalWindow.show();
        waitingWindow.destroy();
    });
}

关于javascript - 如何删除在 Electron 中从 index.html 到 contact.html 的转换过程中创建的空白页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47773305/

相关文章:

javascript - $.getJSON - 发送了 ajax 但忽略了回调函数 - Internet Explorer

html - 为什么样式为按钮的 a 元素与按钮元素的行为不同?

HTML & CSS : Text in one line with span align right full visible

javascript - 如何在不同文件的 JavaScript 中使用来自 PHP 脚本的信息?

javascript - 过滤搜索列表未检索到不可见段落

javascript - 在点击事件中获取所有标签名称

javascript - #each helper 之外的 Handlebars 表达式

javascript - 在有条件的数组中查找局部最大值 [JS]

javascript - 使用 Bootstrap 将 jQuery 应用于正文(背景)但不应用于模态

html - Bootstrap 3 如何在不同列中的相同水平位置设置按钮