Page 1 of 1

How can you call the name of a component or page in JavaScript?

Posted: Wed Dec 11, 2013 12:12 am
by Patrick Kelly

Basically, I have named my pages by category, appending a simple letter to the beginning to indicate what type of page it is. For example, if the page is associated with the "About" section, I append an "a". to the beginning. So, a page that states our mission would normally be called "mission". Instead, because you get to it from the "About" page, it is called "aMission".

I want to make some style modifications dependent on the type of page it is. There are various reasons why simply changing the theme won't work, and I don't want to go into details. So, for example, lets say that I want to change the header color based on the type of page. I want to run JavaScript to change the color based on the type of page, using ifelse statements. Essentially, I want to say "If the page name starts with a, then run this script. If it starts with b, then run this. Else, run this". I know how to write the program, but I need to be able to put the page name into a string variable so that I can use it in the ifelse statement. Is there any way that I can, in JavaScript, call the name of the page and put it into a string variable?


How can you call the name of a component or page in JavaScript?

Posted: Wed Dec 11, 2013 2:12 am
by maxkatz

Are you trying to get the name of the current page?


How can you call the name of a component or page in JavaScript?

Posted: Wed Dec 11, 2013 2:27 am
by Patrick Kelly

Yes


How can you call the name of a component or page in JavaScript?

Posted: Wed Dec 11, 2013 3:52 am
by maxkatz

You can use jQuery Mobile API:

code
$.mobile.activePage.attr('id');
/code