-1

I want to find out, how can i see if there's any character/string after a specific string part from a string. My question sounds ambiguous but here's my real example:

I can have 2 urls : http://domain/classAdd?itemId=1123123 or http://domain/classAdd?ItemId=

I want to put a condition in HTML regarding the url, to have specific header on my site. How can i check if the url has a itemId or not?

At moment i'm getting only :location.indexOf('classAdd?itemId=') == -1 I tried to verify the length but doesn't work. I searched a lot but i didn't find anything to answer my question, only how to get Specific string from a string. My Id is dynamic and the substring won't work

Thank you guys.

Michael Commons
  • 773
  • 2
  • 9
  • 28

2 Answers2

2

check if this

window.location.href.substring(window.location.href.indexOf('classAdd?itemId=') + 16)

gives you the itemId

Aleksandar Matic
  • 789
  • 1
  • 9
  • 21
0
function(){
    var indexOfEqual = window.location.href.indexOf("=");
    if(indexOfEqual < window.location.href.length) return true;
    return false;
}
DrEarnest
  • 853
  • 2
  • 13
  • 27
  • I think this is too general. What if there was e.g. OrderId= instead of ItemId=, it would still return true when really it should return false in TrulyXax's case. – Aleksandar Matic Sep 23 '16 at 13:49