我尝试制作电子应用,但这个脚本不起作用。我真的不知道什么是错的。希望有人可以帮助我吗?
function search() {
const remote = require('electron').remote;
const BrowserWindow = remote.BrowserWindow;
var x = document.getElementById("searchText").value;
var search = x.replace(/ /g, "+");
var searchWindow = new BrowserWindow({
width: 800,
height: 600,
frame: false
});
searchWindow.setPosition(100, 100);
searchWindow.setMenu(null);
searchWindow.loadURL("https://youtube.com/results?search_query=" + search);
searchWindow.webContents.on('will-navigate', function() {
var theUrl = url;
var dWindow = new BrowserWindow({
width: 800,
height: 600,
frame: false
});
dWindow.setPosition(200, 200);
dWindow.setMenu(null);
dWindow.loadURL(theUrl);
}
}
它甚至不创建searchWindow(以及dWindow)。 当我删除它时,searchWindow确实显示(但dWindow没有):
searchWindow.webContents.on('will-navigate', function() {
var theUrl = url;
var dWindow = new BrowserWindow({
width: 800,
height: 600,
frame: false
});
dWindow.setPosition(200, 200);
dWindow.setMenu(null);
dWindow.loadURL(theUrl);
}
在我的HTML代码中我有
<form action=>
<input type="text" placeholder="Search.." id="searchText" />
<input type="button" value="Search.." onclick="search()" id="searchButton" />
<script src="searchFunction/search.js" />
</form>