我已经通过 npm 为我的 node-webkit 项目安装了 jquery
和 jquery-ui
。
我还有一个 index.html
,它在启动时由 node-webkit 加载,并加载一个 core.js
。
这个core.js
需要jquery
和jquery-ui
。当我启动应用程序时,出现 navigator is not Defined
错误。我尝试用谷歌搜索但没有找到解决方案。有谁知道是什么原因造成的?
最佳答案
这个问题与jquery-ui无关。我可以用它来重现它
// index.html
<script>
require('./test.js');
</script>
// In test.js
console.log(navigator);
这是节点require
的限制,only copies over the values of global
,但导航器实际上并不在 global
中。只需指定 navigator
即可在浏览器上下文中工作,因为隐式全局变量不是由 global
提供的,而是由 window
提供的对象(尝试window.x = 2; global.x = 3; console.log(x);
)。
要解决此问题,您只需使用 window
中所需的变量初始化全局,或修复有问题的代码(即 jQuery UI)以在 window 前面添加对导航器的引用。
。这应该适用于 jQuery UI:
global.document = window.document;
global.navigator = window.navigator;
require('jquery-ui');
关于javascript - 需要 ('jquery-ui' ) 在 node-webkit 中产生导航器未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25764696/