Reputation: 10919
I am trying to get my applications root URL from within a .js file. A solution I came upon suggested to use:
window.location.origin
However, because the site is hosted in a virtual directory in IIS, that only returns http://www.whatever.com
, but I need it to return http://www.whatever.com/mydir
. This might seem like simple string parsing, but I debug using localhost where there is no virtual dir, so I need a solution that is available from with a .js file (not a script block within an HTML document) and is dynamic in that it will work with and without a virtual directory.
Upvotes: 3
Views: 1298
Reputation: 943547
There is no way to do this from client side code.
The browser only knows about URLs. It has no way to know how you used them to organise your site.
If you want to tell the browser the /mydir
is special, then you'll need to encode that in the data you send to it (e.g. in a <meta>
element).
Upvotes: 3