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,221
  • 6
  • 23
  • 44

5 Answers5

3

Try this.

if(location.hash.indexOf('&ui-page=globalMenu') != -1){
   //It ends with #&ui-page=
}
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
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,762
  • 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
  • 37,158
  • 8
  • 76
  • 101
1

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

Kris Erickson
  • 33,454
  • 26
  • 120
  • 175
1
 if(/#&ui-page=globalMenu-[0-9]+/.test(location.hash))
     {
         // do stuff
     }
gion_13
  • 41,171
  • 10
  • 96
  • 108