2015-12-16 14 views
0

添加變量作爲輸入我想使用這個幻影代碼,但使用的是Node.js,但我不覺得system.args [1]在node.js的等效的Node.js:如何在URL

var phantom = require('phantom'); 
    // var page = new WebPage(); 
    // var system = require('system'); 
    // var sBlob = system.args[1]; 
    var sUrl = 'file:///C:/Users/editor.html?Blob='+sBlob; 
    phantom.create(function(ph) { 
     ph.createPage(function(page) { 
      page.open(sUrl, function(status) { 
       console.log("opened diagram? ", status); 
       page.evaluate(function() { 
        return document.getElementById("GraphImage").src; 
       }, function(result) { 
        console.log(result) 

        ph.exit(); 
       }); 
      }); 
     }); 
    }, { 
     dnodeOpts : { 
      weak : false 
     } 
    }); 
+3

【如何命令行參數傳遞給Node.js的?(HTTP的可能重複:// stackoverflow.com/questions/4351521/how-to-pass-command-line-argu ments-to-node-js) – SWeko

+0

@sweko我希望能夠傳遞sBlob,它是url的輸入 – ameni

回答

0

如果您運行的腳本$ node script.js theargument

你應該能夠用得到它

// the first argument is node and 
//the second is the script name, none of them should be relevant 
var args = process.argv.slice(2); 
var sBlob = args[0];