window.location.origin works fine but my application is hosted in different directory, I mean, root url of production is xyz.com/InnerDirectory. On local host window.location.origin works but on production it gives xyz.com but I need xyz.com/InnerDirectory How can I achieve this?
Asked
Active
Viewed 1,910 times
0
Imad
- 7,126
- 12
- 55
- 112
-
4How do you expect the browser to know the root of your application? – gdoron Aug 14 '15 at 11:59
-
hmm. right. means there is no way using javascript? other ways? – Imad Aug 14 '15 at 12:03
-
I suggest you use a `switch` like here: http://stackoverflow.com/questions/12259958/javascript-site-root. – SmartDev Aug 14 '15 at 12:06
1 Answers
1
Javascript can't know what's the the root path of your application.
But since you tagged your question with asp.net, you can use virtual paths and asp.net will handle the paths for you.
So instead of:
<sometag src="xyz.com/InnerDirectory/something.css">
Write this:
<sometag src="~/something.css">
BTW, if you use ASP.NET MVC, it's even easier as you should use the @Url.Content \ Url.Action helpers
gdoron
- 147,333
- 58
- 291
- 367