node open打开浏览器

前言:

本文其实来自司徒的《node.js打开浏览器》,但是方法过于单一,收录了MK2的代码,感谢作者!

正文:

node打开浏览器:

var child_process = require("child_process"),
    url = "http://www.baidu.com";

if(process.platform == 'wind32'){

       cmd  = 'start "%ProgramFiles%Internet Exploreriexplore.exe"';

}else if(process.platform == 'linux'){

       cmd  = 'xdg-open';

}else if(process.platform == 'darwin'){

       cmd  = 'open';

}

child_process.exec(cmd + ' "'+url + '"');

扩展阅读:

https://github.com/fengmk2/fawave_desktop/blob/master/src/js/shell.js