javascript - 如果window.location以html结尾则执行javascript

标签 javascript jquery search window.location

如果当前位置包含 html,则执行 javascript。我已尝试以下操作,但不起作用

var winloc = window.location; //for e.g http://mysite.com/home.html
var ishtml = winloc.match(/html/$);
var dothtml = "html";
if(dothtml==ishtml){
//execute javascript here
}

最佳答案

var isHTML = "html" === window.location.pathname.split(".").pop().toLowerCase();
if ( isHTML ) {
    //execute javascript here
}

使用正则表达式查看 Amaan 答案:

https://stackoverflow.com/a/8619635/887539

关于javascript - 如果window.location以html结尾则执行javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8619552/

相关文章:

javascript - jQuery flot - 适合时间轴刻度标签,没有文本溢出可变范围图表

javascript - 如何在 Vue 组件中使用 Bootstrap?

javascript - jQuery 显示 div 加载 onclick

c++ - 通过多个标签搜索数据集

javascript - 单独的 Div 中的多个 Google 可视化图表实例

javascript - Angular js-值更改时突出显示dom

javascript - 如何在屏幕上显示另一个 div 时隐藏一个 div。

javascript - 需要使用变量列表中的文本更改 <a> 的文本

java - 使用的 Lucene 搜索库算法

python - 在numpy数组中查找最近的值