节点webkit中的Require('jquery ui')产生navigator not found错
Require('jquery-ui') in node-webkit produces navigator not found error
我已经通过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
的限制,它只复制global
的值,但navigator实际上不在global
中。仅指定navigator
在浏览器的上下文中有效,因为隐式全局变量不是由global
提供的,而是由window
对象提供的(请尝试window.x = 2; global.x = 3; console.log(x);
)。
要解决这个问题,您可以简单地使用window
中所需的变量初始化global,或者修复有问题的代码(即jQueryUI),以使用window.
预先发送对navigator的引用。这应该适用于jQuery UI:
global.document = window.document;
global.navigator = window.navigator;
require('jquery-ui');
相关文章:
- chrome扩展中的navigator.geolocation.getCurrentPosition
- React Native通过Navigator将用户输入数据传递到选项卡栏IOS中的组件
- 函数产生错误的差异
- 使用(navigator.geolocation)检测浏览器功能错误
- 离子2:在离子载玻片内产生ng重复
- javascript RegExp的奇怪行为:相同的正则表达式会产生不同的结果
- 在百度地图中显示navigator.geolocation.getCurrentPosition
- 类型错误'未定义'不是对象(正在评估'navigator.connection.type'
- JSON.stringify和Object.keys在同一个对象上产生不同的结果
- 使用navigator.getUserMedia(Javascript)访问移动麦克风
- 嵌套承诺会产生类似的效果
- 如何拆分一个整数和产生的所有数字来创建一个新数字
- Replace()产生“;未捕获的类型错误:未定义的不是函数“;当与零一起使用时
- ember.js:转换到相同的路由会产生堆栈溢出问题
- 我可以从内部函数中产生吗?
- 在React Native+Redux中使用Navigator
- Angular2-*ngFor和*ngIf在同一个元素上产生错误
- 在safari和chrome中,js图像加载产生了奇怪的结果
- jQuery$.每个都正常工作,但产生TypeError
- 节点webkit中的Require('jquery ui')产生navigator not found错