如果当前位置包含 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 答案:
关于javascript - 如果window.location以html结尾则执行javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8619552/