0

I have a web server setup. And my web app (JQuery + HTML) is up and running. I would like to use the path that is provided in the URL as some variable and perform different operation.

E.g.

http://subdomain.mydomain.com/
This points to /var/www , and has my index.html

I am trying to achieve the functionality that, when path with some value is provided, e.g.

http://subdomain.mydomain.com/c3212

I will catch the value c3212 in javascript and set it as some static variable. The view/js code in index.html uses this code to make requests to server to fetch some data and layout the data accordingly.


How do I go about doing this ? Googling didn't help much, since I don't actually know what terms should I search for. Do I also need to make changes in Apache VirtualHost configuration?

I am not a web guy, help would be appreciated, thank you.

3
  • window.location will give you information regarding the current page. you can then use that info to base your functions on. Commented Jun 5, 2013 at 21:00
  • Are you looking to get this value in JS or on your server? You did mention javascript in your question, but if so, Apache VirtualHost has nothing to do with it. Commented Jun 5, 2013 at 21:04
  • Ya I am trying to get this value in JS. Ya I realized it might not have anything to do with VirtualHost config. What I am trying is basically to catch the url parameter /c3212 in my index.html/js. Commented Jun 5, 2013 at 21:15

1 Answer 1

1

You can use the window.location JavaScript object to get the path like so:

var path = window.location.pathname;
console.log(path); // this will output "/c3212" based on your example

Once you have this you can use it with the rest of your script.

I hope this helps!

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

1 Comment

Do I need to modify .htaccess in order to prevent NOT found ? and so that they will be caught under index.html ?

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.