检查URL和运行功能

Check URL and running function?

本文关键字:功能 运行 URL 检查      更新时间:2023-09-26

有一个关于URL和jQuery或JavaScript的问题。

如果域栏与www.example.com等效,如何运行脚本?

如果域栏与www.example.com和子URL等效,则运行脚本,例如www.example.com/suba、www.example.com/ssubb.

我可以指定URL来告诉jQuery运行函数吗?

抱歉我英语不好:D

感谢

数百万在线教程。

所以你需要:

  • 1检查正确的URL:使用window.location.href或其他window.location属性
  • 2如果需要,运行函数:if(condition) functionName();

这就是它最终的样子:

if (window.location.href.indexOf('www.example.com') != -1) {
    // run script here
}