2011-10-05 21 views

Odpowiedz

64

Opn istnieje teraz, użyj tego. :)

Instalacja z:

$ npm install --save opn 

użytku z:

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

Co o Linuksie i Windows? – chovy

+2

Uważam, że xdg-open jest standardową wersją otwartą dla systemu Linux, ale nie mam pojęcia, czego używałbyś w systemie Windows. – ctide

+9

https://github.com/fixedset/open.js zajmuje się problemem x-platform –

Powiązane problemy