【发布时间】:2020-03-06 19:04:04
【问题描述】:
我正在尝试学习 Electron js。 我的 index.html 中有一个非常简单的 HTML
<!doctyp html>
... all the other normal declarations ...
<button class="alert">alert</button>
<script>
const btn = document.querySelector('.alert');
btn.addEventListener('click', () => { alert('alerting');})
</script>
由于某种原因,这在 Electron 中不起作用。当我在任何其他网络浏览器中运行此代码时,它运行良好。怎么回事?
谢谢
【问题讨论】:
-
stackoverflow.com/questions/38858879/… - Electron 不支持
alert,因为它会阻塞执行流程。使用 Electrons 内置对话框来实现类似的非阻塞效果。 -
@somethinghere 这最多是事实的一半。只需阅读所有文本并评论链接的答案。我们可以调用
window.alert,因为电子为此提供了一个实现。只是window.prompt不起作用,我们需要自定义实现,例如electron-dialog。 -
当我刚刚在我的脚本标签中写了``` ```。它显示了一个警报,但是当使用事件侦听器时它不起作用