0

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?

3
  • 4
    How do you expect the browser to know the root of your application? Commented Aug 14, 2015 at 11:59
  • hmm. right. means there is no way using javascript? other ways? Commented Aug 14, 2015 at 12:03
  • I suggest you use a switch like here: stackoverflow.com/questions/12259958/javascript-site-root. Commented Aug 14, 2015 at 12:06

1 Answer 1

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">

Read more here.

BTW, if you use ASP.NET MVC, it's even easier as you should use the @Url.Content \ Url.Action helpers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.