How to check if the URL is part of the string. Full view string

index.php?route=catalog/product/edit&user_token=BrNypCZLBTKEZLU04b0YatYdMo5YmLRd&product_id=51 

I try to check, but in vain, what exactly is my mistake and how to do it

 <script> var path = window.location.search; if (path.match("/^\?route=catalog/product/edit$/")) alert ("yes") </script> 

    1 answer 1

    search() or indexOf() . Both return the position from which the desired substring starts, or -1 if the substring in the string is not found.

      var path = "index.php?route=catalog/product/edit&user_token=BrNypCZLBTKEZLU04b0YatYdMo5YmLRd&product_id=51"; var n = path.search("route=catalog/product/edit"); if (n => 0 ) alert ("yes"); 

    or

      var path = "index.php?route=catalog/product/edit&user_token=BrNypCZLBTKEZLU04b0YatYdMo5YmLRd&product_id=51"; var n = path.indexOf("route=catalog/product/edit"); if (n => 0 ) alert ("yes");