0

I was wondering how I would get the hostUrl in JavaScript which is passed from the command line

In Java, one would type System.getProperty("hostUrl"); to achieve this. What is the alternative to this in JavaScript?

user2996905
  • 125
  • 1
  • 6
  • http://stackoverflow.com/questions/1368264/get-host-name-in-javascript – Sunil Singh Bora Feb 12 '14 at 11:00
  • What do you mean by: 'which is passed from command line'? In js, you could get the host url by using: `window.location.protocol + "//" + window.location.hostname` – Nicolae Olariu Feb 12 '14 at 11:01
  • Maybe you are looking for this: [How to accept command-line arguments in JScript?](http://blogs.msdn.com/b/subashb/archive/2004/02/20/77151.aspx) – ViToni Feb 12 '14 at 11:06
  • Hi , thanks for guiding me , but this does not work out ,i have tried both the way. when i run the JS test cases i need the hostUrl in my testcases which is passes from the commmand line when i do maven test "mvn test -DhostUrl=http://abc.xyz.pqrs:8080" – user2996905 Feb 12 '14 at 11:30

1 Answers1

0

I am assuming that you are searching for window.location.hostname or window.location.host.

ˈvɔlə
  • 9,204
  • 10
  • 63
  • 89
  • Hi , thanks for guiding me , but this does not work out ,i have tried your way. when i run the JS test cases in maven with PhantomJS i need the hostUrl in my testcases which is passes from the commmand line when i do maven test "mvn test -DhostUrl=abc.xyz.pqrs:8080" . I need this url in my test cases. – user2996905 Feb 13 '14 at 09:10
  • Whats the value of `window.location.hostname` or `window.location.host` in your case? – ˈvɔlə Feb 13 '14 at 09:18
  • So, if it is returning null, window.location is defined. Maybe you find some useful properties on the window.location object. If not, maybe you can find something in the official PhantomJS API: http://phantomjs.org/api/. Otherwise, there is no chance, that such a property is available in ECMAScript – ˈvɔlə Feb 13 '14 at 09:37
  • 1
    well , Am using phantomJS with jasmine to run my javascript test cases. I am passing hostUrl from the maven command line and i am taking that hosturl in phantom file by phantom.args[1] , am getting the hostUrl which is passed from maven command line . So, now i need this hosturl to be access in my jasmine test cases javascript file . How to pass this url from phantom file to the javascript file . Thanks ! – user2996905 Feb 13 '14 at 11:55