如果window.location以html结尾,则执行javascript [英] If window.location ends with html execute javascript
本文介绍了如果window.location以html结尾,则执行javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果当前位置中包含html,则执行javascript.我尝试了以下操作,但不起作用
Execute javascript if current location contains html in in. I have tried the below but it doesn't work
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答案:
See Amaan answer using regexp:
https://stackoverflow.com/a/8619635/887539
这篇关于如果window.location以html结尾,则执行javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文