【发布时间】:2021-11-24 01:12:07
【问题描述】:
我想使用自定义按钮为我的无框窗口添加自定义标题。
我有两个脚本文件 - index.js,在 Electron 启动时自动运行,app.js,在 index.html 中添加了 <script src> 标签。
有一个问题 - require() 不让脚本工作 - 如果我需要任何模块,则不会运行任何行,不管它是什么。
index.html:
<head>
...
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="app.js"></script>
...
</head>
index.js
const {app, BrowserWindow} = require('electron')
const path = require('path')
const sass = require('sass')
const fs = require('fs')
// Creates a main window
function createWindow () {
renderStylesheets()
let mainWindow = new BrowserWindow({
width: 800,
height: 600,
resizable: true,
transparent: true,
frame: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
mainWindow.loadFile('index.html').then(() => {})
}
...
app.js
alert("This alert won't show.")
// If I remove these lines, alerts and jQuery's "$(callback)" will run, but
// button actions won't work :(
const { BrowserWindow, app } = require('electron').remote;
let window = BrowserWindow.getFocusedWindow();
alert("This alert won't show and the $(() => {}) won't run too.")
...
【问题讨论】:
标签: javascript html node.js electron