0

I'm manipulating a nested list in jquery mobile. I need to run a check if the url ends with x#&ui-page=globalMenu-"and a number". How can I do this?

ex for a url

www.test.no/Site/default.aspxx#&ui-page=globalMenu-7

I want to check if the site ends/contains #&ui-page=globalMenu

Plexus81
  • 1,211
  • 5
  • 22
  • 43

5 Answers5

3

Try this.

if(location.hash.indexOf('&ui-page=globalMenu') != -1){
   //It ends with #&ui-page=
}
ShankarSangoli
  • 68,720
  • 11
  • 89
  • 123
3

window.location.hash will give you access to #&ui-page=globalMenu-7.

So the following code will do what you want:

var matches = window.location.hash.match(/#\&ui-page=globalMenu\-([0-9])?/);

For the example you give:

matches[0] will contain: #&ui-page=globalMenu-7

and matches[1] will contain: 7

extols
  • 1,752
  • 14
  • 19
2

Just check the value of window.location.hash for equality with your desired string.

Example:

Url: http://stackoverflow.com/questions/8929224/jquery-if-url-window-location-pathname-ends-with-ui-page/8929249#8929249

Value of window.location.hash: #8929249

wsanville
  • 36,693
  • 7
  • 74
  • 101
1

In javascript window.location.hash will give you then hash of your url.

Kris Erickson
  • 32,972
  • 26
  • 117
  • 173
1
 if(/#&ui-page=globalMenu-[0-9]+/.test(location.hash))
     {
         // do stuff
     }
gion_13
  • 40,487
  • 10
  • 96
  • 107