2011-10-05 7 views

Respuesta

64

Opn existe ahora, úselo. :)

instalar con:

$ npm install --save opn 

uso con:

const opn = require('opn'); 

// Opens the image in the default image viewer 
opn('unicorn.png').then(() => { 
    // image viewer closed 
}); 

// Opens the url in the default browser 
opn('http://sindresorhus.com'); 

// Specify the app to open in 
opn('http://sindresorhus.com', {app: 'firefox'}); 

// Specify app arguments 
opn('http://sindresorhus.com', {app: ['google chrome', '--incognito']});var open = require('open'); 

    open('http://www.google.com'); 

You can also select a specific browser: 

    open('http://www.google.com', 'firefox'); 

Or handle an error callback: 

    open('http://www.google.com', function (err) { 
     if (err) throw err; 
     console.log('The user closed the browser'); 
    }); 
+4

¿Qué pasa con Linux y Windows? – chovy

+2

Creo que xdg-open es la versión estándar de open para Linux, pero no tengo idea de qué usarías para Windows. – ctide

+9

https://github.com/fixedset/open.js maneja el problema de la plataforma x –

Cuestiones relacionadas