我需要一些關於我使用Electron構建的應用程序的專業JavaScript幫助。問題的關鍵在於,如果我遠離主頁面(index.html)並簡要導航回頁面,但顯着地顯示構成垂直選項卡式菜單的div和ul元素(位於,)在頁面的左側(見下面的圖片)。
我的同事和我似乎無法弄清楚,也不能在整個網絡上找到足夠的信息是如何解決或調整這一點。有人建議我們知道,也許構建某種渲染器來維護與Main.js中創建的不同窗口線程,但他不知道我們怎麼也沒有找到有關如何執行此操作的信息。這是正確的道路嗎?
或者這只是一個錯誤的地方或丟失的代碼的情況下,保持每一次正確加載頁面?
還是別的什麼都一起?任何援助將不勝感激,因爲我的背部在解決這個問題上是在牆上。先謝謝你!
BrowserWindow在電子應用中的渲染
的index.html渲染:
的Index.html後呈現:
Main.js:
const electron = require('electron');
// Module to control application life.
const {app} = electron;
// Module to create native browser window.
const {BrowserWindow} = electron;
var express = require('express');
var expressapp = express();
var hostname = 'localhost';
var port = 3000;
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 1920,
height: 1080,
webPreferences: {
nodeIntegration: true,
resizable: true,
fullscreenable: true,
maximizable: true,
minamizable: true,
movable: true,
autoHideMenuBar: false,
allowDisplayingInsecureContent: true,
allowRunningInsecureContent: true
}
})
// and load the index.html of the app.
win.loadURL(`file://${__dirname}/index.html`);
// Open the DevTools.
win.webContents.openDevTools();
// Emitted when the window is closed.
win.on('closed',() => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed',() => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate',() => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow();
}
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
expressapp.use(express.static(__dirname + '/public'));
expressapp.listen(port, hostname, function() {
console.log(`Server running at http://${hostname}:${port}`);
});
的Index.html代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type:"text/css" href="css/jquery-ui.min.css">
<link rel="stylesheet" type:"text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type:"text/css" href="css/jquery.scrollbar.css">
<link rel="stylesheet" type:"text/css" href="css/tabs.css">
<link rel="stylesheet" type:"text/css" href="css/persian-datepicker-0.4.5.min.css">
<link rel="stylesheet" type:"text/css" href="css/clockpicker.css">
<link rel="stylesheet" type:"text/css" href="styles.css">
<link rel="stylesheet" type:"text/css" href="css/entry.css">
<link rel="stylesheet" type:"text/css" href="css/navbar.css">
<link rel="stylesheet" type:"text/css" href="css/modal.css">
<meta id="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
...
<form name="mainForm">
<div id="sections">
<ul>
<li><a href="#section1">Section 1</a></li>
<li><a href="#section2">Section 2</a></li>
<li><a href="#section3">Section 3</a></li>
<li><a href="#section4">Section 4</a></li>
<li><a href="#section5">Section 5</a></li>
<li><a href="#section6">Section 6</a></li>
<li><a href="#section7">Section 7</a></li>
<li><a href="#section8">Section 8</a></li>
<li><a href="#section9">Section 9</a></li>
<li><a href="#section10">Section 10</a></li>
<li><a href="#section11">Section 11</a></li>
</ul>
...
<script>
window.jQuery = window.$ = require('jquery');
</script>
<script src="js/jquery-ui.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.scrollbar.min.js"></script>
<script src="js/persian-date.min.js"></script>
<script src="js/persian-datepicker-0.4.5.min.js"></script>
<script src="js/clockpicker.js"></script>
<script src="js/jqwidgets/jqxcore.js"></script>
<script src="js/jqwidgets/jqxexpander.js"></script>
<script src="js/jqwidgets/jqxinput.js"></script>
<script src="js/jqwidgets/jqxpasswordinput.js"></script>
<script src="js/jqwidgets/jqxbuttons.js"></script>
<script src="js/jqwidgets/jqxvalidator.js"></script>
<script src="js/data.js"></script>
<script src="js/model.js"></script>
<script src="js/view.js"></script>
<script src="js/form-init.js">
</script>
</form>
</body>
</html>
修改過的瀏覽器窗口代碼:
let win;
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
show: false,
width: 1920,
height: 1080,
backgroundColor: '#4d6b9e',
webPreferences: {
nodeIntegration: true,
resizable: true,
fullscreenable: true,
maximizable: true,
minamizable: true,
movable: true,
autoHideMenuBar: false,
allowDisplayingInsecureContent: true,
allowRunningInsecureContent: true
}
})
win.loadURL(`file://${__dirname}/index.html`);
// and load the index.html of the app.
win.once('ready-to-show',() => {
win.show()
})
感謝您的評論@Vadim。我讚賞考慮。 首先,我可能沒有很好地描述這個問題。基本上,第二張圖片是第一次進入時頁面的外觀。第一張照片是你進入時短暫看到的(〜1秒)。在選項卡式環境下的無序列表顯示它不應該顯示的時間。可悲的是,改變背景顏色並不能解決這個問題。 其次,我沒有聽說過有關在Electron中使用Express服務器的情況。這是爲什麼?在您發表評論之前,我沒有在網上看到任何關於不使用它的信息。 – Steve
@Steve所以這聽起來像你有一些元素被渲染沒有樣式,然後風格是不久後應用。嘗試創建隱藏的瀏覽器窗口,然後在啓動['ready-to-show']時使其可見(http://electron.atom.io/docs/api/browser-window/#using-ready-to- show-event)事件。 –
@Steve至於'express' ...如果您在應用程序/本地運行'express'服務器,這意味着您的所有資源都可以在本地使用,那麼Electron可以直接從磁盤加載'.html'文件和所有相關資源,那麼旋轉HTTP服務器有什麼意義呢?此外,當用戶在瀏覽器中打開遠程網站時,該網站上的JavaScript可以訪問運行在用戶計算機上的HTTP服務器,請閱讀[趨勢科技漏洞利用程序](https://bugs.chromium.org/p /項目零/問題/細節?ID = 693&導向= 1)。 –