Imad
Imad

Reputation: 7490

Get root path of application in javascript

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?

Upvotes: 0

Views: 2387

Answers (1)

gdoron
gdoron

Reputation: 150313

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

Upvotes: 1

Related Questions