【发布时间】:2018-03-28 17:21:27
【问题描述】:
我是 Electron 的新手(就像英语一样 :)。
在加载和呈现主窗口的内容后,我试图输出一个简单的alert。
index.html:
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css">
<title>Test</title>
</head>
<body>
...
Here's some content and images. A lot of them.
...
<script src="alert.js"></script>
</body>
</html>
alert.js:
//Simple alert with some system information
alert("!@#$%^&*");
但在绘制窗口内容之前会出现警告。 Defer 和 async 没有帮助(即 <script defer async src="alert.js"></script>)。我究竟做错了什么?在我看来,这是一个非常简单和愚蠢的问题,但我找不到答案。
UPD:
我目前找到的唯一方法是使用setTimeout:
setTimeout(function(){
alert("!@#$%^&*");
}, 300);
【问题讨论】:
-
我认为脚本在您的正文内容被获取并发送到解析后运行,在内容渲染后运行 alert.js,在 jquery 中,您应该尝试
$(window).on('load', function(){ alert("sdfsd"); }) -
@Rahul Jain。我还没有熟悉jquery。我在哪里插入此代码?
-
你不需要 jQuery:
window.addEventListener("load",x=>alert("hello world")) -
@HMR。此代码也显示了在渲染窗口内容之前的警报。
标签: javascript electron