javascript - 如何在 NW.js 的服务页面中运行脚本?

标签 javascript node.js nw.js

我正在尝试使用 nw.js 打包桌面应用程序。 应用程序导航到由 xampp 服务器提供服务的页面,该服务器位于应用程序运行的同一台计算机上。

当 nw.js 通过 file://导航到页面时,脚本加载成功。

当它通过 http://导航时,脚本不会加载。

控制台中的错误是:

Uncaught ReferenceError: require is not defined

我该如何解决这个问题?我需要它通过 http 加载,因为该应用程序使用 php 来实现几个基本功能。

最佳答案

这是一个使用 Node 远程的示例。

package.json

{
  "main": "http://localhost:3030/",
  "name": "nw-demo",
  "description": "demo app of node-webkit",
  "version": "0.1.0",
  "node-remote" : "localhost:3030",
  "window": {
    "title": "node-webkit demo",
    "toolbar": true,
    "frame": true,
    "position": "center"
  }
}

本地主机上的 html 文件

<script>document.write(require, process);</script>

nwjs (v0.12.3) 应用输出

function (name) { if (name == 'nw.gui') return nwDispatcher.requireNwGui(); return global.require(name); }[object process]

关于javascript - 如何在 NW.js 的服务页面中运行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34733540/

相关文章:

node.js - 尝试创建我的第一个 Node.js 应用程序 :/bin/sh: 1: fpm: not found

javascript - 为什么我无法将函数传递给 Function 构造函数?

javascript - 部分滚动缩放动画

node.js - 添加多个占位符时快速路由不起作用

javascript - 如何将传入的文件流从 Node 保存到 AngularJS

javascript - 如何使用 Multer 验证 Express 中文件上传的大小?

javascript - 如何更改 NW.js 中的 JSON 保存位置/目录

javascript - 使用 angularjs 创建水平单选按钮

javascript - javascript ajax 无法正常工作

javascript - 在 Controller 异步调用后添加 CSS 样式的首选 AngularJS 方式是什么?