How do I tell jQuery to run a function on one specific web page only?

前端 未结 4 1882
臣服心动
臣服心动 2021-02-18 21:57

I have some jQuery code that is on every web page of the site (in the head element).

What selector syntax can I use to tell jQuery that a certain function should only ru

4条回答
  •  耶瑟儿~
    2021-02-18 22:34

    Maybe check window.location.pathname?

    if (window.location.pathname == "/path/to/page.html") {
        callFunction();
    }
    

提交回复
热议问题