gpt4 book ai didi

javascript - 单击按钮但不打开窗口或链接 Electron

转载 作者:行者123 更新时间:2023-11-30 13:54:57 24 4
gpt4 key购买 nike

我正在编写一个程序来监控 Steam 市场上的价格,并在 Electron 中构建一个 UI,问题是当我单击一个按钮时它没有注册。

我曾尝试将其记录到控制台或发送到新窗口或打开链接,但它不起作用。我也厌倦了使用 .on('click', ....

index.js:

const {BrowserWindow} = require('electron').remote
const path = require('path')
const {shell} = require('electron')
const launchbtn = document.getElementById('launch')

launchbtn.addEventListener('click', (event) => {
const modalPath = path.join('file://', __dirname, 'launch.html')
let win = new BrowserWindow({ width: 400, height: 320 })
//shell.openExternal('http://electron.atom.io') tried but didnt work
win.on('close', () => { win = null })
win.loadURL(modalPath)
win.show()
})

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" href="../assets/css/main.css">
</head>
<body>

<div class="row">
<div id="price-container">
<p class="subtext">Market-Monitor</p>
<h1 id="About">By SourcE</h1>
</div>
<div id="goal-container">
<p><span id="targetPrice">Monitor Prices of items</span></p>
</div>
<div id="right-container">
<button id="launch">Launch</button>
</div>
</div>

<script src="index.js"></script>
</body>
</html>

启动.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" href="../assets/css/main.css">
</head>
<body>

<div class="row">
<div id="price-container">
<p class="subtext">test</p>
<h1 id="About">test</h1>
</div>
<div id="goal-container">
<p><span id="targetPrice">test</span></p>
</div>
<div id="right-container">
<button id="launch">test</button>
</div>
</div>

<script src="index.js"></script>
</body>
</html>

如果按钮正常工作,它应该打开一个新的窗口实例,并将文本更改为文本。

感谢任何帮助。

最佳答案

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code> <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" href="../assets/css/main.css">
</head>
<body>

<div class="row">
<div id="price-container">
<p class="subtext">test</p>
<h1 id="About">test</h1>
</div>
<div id="goal-container">
<p><span id="targetPrice">test</span></p>
</div>
<div id="right-container">
<form name="form-name" action="launch.php">
<input type="submit" name="submit" value="Button Name">
</form>
</div>
</div>

<script src="index.js"></script>
</body>
</html></code></pre>
</div>
</div>

新文件将其命名为 launch.php

<?php

if ( isset( $_POST['submit'] ) ) {

header("Location: <LINK>");

}
?>

关于javascript - 单击按钮但不打开窗口或链接 Electron,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57493098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com