Can jQuery detect a specific URL and perform a function based off that URL?

后端 未结 3 807
Happy的楠姐
Happy的楠姐 2021-01-15 03:24

I have a site I\'m working on. I need to be able to perform a specific function if the URL matches a specific URL. Here\'s an example of what I\'m trying to do:

If

相关标签:
3条回答
  • 2021-01-15 03:50

    Probably will be better to use the querystring location.search than location.href. This would cover subdomains/protocol changes.

    if(location.search == "?l2=3,15,25")
        $('.content').addClass('show');
    
    0 讨论(0)
  • 2021-01-15 03:54

    You seem to be looking for the location object, which contains information about the URL of the current page.

    0 讨论(0)
  • 2021-01-15 04:09
    var url = "http://www.example.com/EIFS-items/search.php?l2=3,15,25";
    $(function(){
      if (location.href==url){
        $('.content').show();
      }
    });
    
    0 讨论(0)
提交回复
热议问题