0

i was wondering if its possible to run an event based on url with asterix. So for example lets say i want to run an event if i'm on https://mypage.com but i also want to run the event on https://mypage.com/?page=2 and page 3 and page 4 etc is there any way to do this in javascript. I thought something like this should work

if(window.location.href == "https://mypage.com/*") {
    alert("Yes");
} else{
    alert("No");
}

But it returns No

Tim Levinsson
  • 597
  • 2
  • 7
  • 20
  • 1
    Use RegExp or in this case `startsWith`. – t.niese May 26 '18 at 17:14
  • [Wildcard string comparison in Javascript](https://stackoverflow.com/questions/26246601/wildcard-string-comparison-in-javascript) – Jonathan Lonowski May 26 '18 at 17:15
  • Possible duplicate of [How to check in javascript if url address start with defined string?](https://stackoverflow.com/questions/21518395/how-to-check-in-javascript-if-url-address-start-with-defined-string) – t.niese May 26 '18 at 17:16

0 Answers0