1

我试图找出是否可以从网页调用 node.js 函数。有什么方法可以让 Google Chrome 访问 node.js 函数(以便它们在 node.js 服务器上运行),如此处所示?

(我知道可以在不修改代码的情况下使用node-webkit(一种非标准 Chromium 实现)来执行此操作,但我更喜欢使用未修改的浏览器来执行此操作,这将需要下面显示的代码以某种方式修改。)

<html>
    <body>
        <script type = "text/javascript">
            var exec = require('child_process').exec; //node.js function
        </script>
        <p onclick = "exec('firefox')">
            Click here to launch the Firefox web browser.
        </p>
   </body>
</html>
4

2 回答 2

2

NW 有自己的方法,例如 node exec :

var gui = require('nw.gui');
gui.Shell.openItem('firefox', ,function(error, stdout, stderr) { });
于 2012-11-20T05:42:03.757 回答
2

不,这是不可能的,出于明显的安全原因。

您只能使用浏览器为您提供的内容。 node-webkit是最接近可用的东西,并且不符合您的要求。

于 2012-11-18T05:43:39.907 回答