17

I can parse are HTTP response of one of the intial calls and save that in the state but there must be another way to get the URL?

I am using the npm 'rest' library and want to specify a different port but I do not know the path on which machine the server will be installed so I need the server's url.

Solution

window.location.hostname

ALM
  • 2,555
  • 7
  • 31
  • 45
  • 2
    window.location.href – omarjmh Jun 15 '16 at 00:00
  • 1
    Thanks I just found that as well :) – ALM Jun 15 '16 at 00:01
  • Why down vote this, I spent time googling for a answer and trying different things. All of them were related to the clients IP not server. – ALM Jun 15 '16 at 00:05
  • 2
    Not the downvoter, but you should mark the correct answer (not write solution in your own question). If no answers are correct, and you found your own solution, submit that as an answer and mark it correct – Chris Jun 15 '16 at 00:08
  • Possible duplicate of [Get current URL in JavaScript?](http://stackoverflow.com/questions/406192/get-current-url-in-javascript) – Alex McMillan Jun 15 '16 at 00:11
  • @Chris at the time there was no answer provided so I posted the solution I used which was also a comment. I later marked the answer correct when the user posted it not just in comments. – ALM Jun 15 '16 at 14:37

1 Answers1

40

location is a property on the window object with a bunch of information, you can get the url with window.location.href

You can get the hostname with window.location.hostname

ALM
  • 2,555
  • 7
  • 31
  • 45
omarjmh
  • 13,632
  • 6
  • 34
  • 42
  • Thanks for some reason I didnt think I had access to this. I just found it prior to your answer ;) – ALM Jun 15 '16 at 00:03
  • 2
    nit: window.location doesn't return anything. It's not a function. – Ryan Jun 15 '16 at 00:03