Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 10
    This works with URL string where location object is not available(js outside browser!) Commented Nov 26, 2014 at 6:03
  • 12
    Or just turn it into a one-liner: window.location.href.split('/').slice(0, 3).join('/') Commented May 16, 2017 at 19:35
  • and how you'd do this on node? Commented May 22, 2017 at 10:49
  • It looks like location.protocol is supported since may 2013. When this answer was made it made sense, for now you could use location.protocol.
    – A1rPun
    Commented Sep 16, 2019 at 14:41