2016-01-12 249 views
0

我正在嘗試使用nw.js打包桌面應用程序。 應用程序將導航到正在運行應用程序的同一臺計算機上從xampp服務器提供的頁面。如何在NW.js中的服務頁面中運行腳本?

當nw.js通過file導航到頁面時// //腳本加載成功。

當它通過http://導航時,腳本無法加載。

在控制檯中的錯誤是:

Uncaught ReferenceError: require is not defined 

我怎樣才能解決這個問題?我需要它通過HTTP加載,因爲該應用程序使用PHP的幾個基本功能。

+0

你應該允許它通過清單。 https://github.com/nwjs/nw.js/wiki/manifest-format#node-remote 另見http://stackoverflow.com/questions/29295404/node-webkits-nwjs-node-remote-usage – Fella

+0

'via http://'你有正確的主機名嗎? –

+0

@Fella就是這樣。我使用節點遠程基於我在另一個網站上看到的評論,但它失敗了,所以我很頭疼。我看着你發來的網頁,並澄清什麼,我看到了其他頁面上: https://github.com/nwjs/nw.js/issues/2679 後你回答,我會標記爲正確的。 我必須設置該屬性爲「節點遠程」:「127.0.0.1」 – xerotolerant

回答

1

以下是node-remote的示例。

的package.json在localhost

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

nwjs(v0.12.3)應用程序輸出

函數(名稱){如果(名稱

{ 
    "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文件==' nw.gui')return nwDispatcher.requireNwGui(); return global.require(name); }對象過程]

相關問題