如果window.location以html结尾则执行javascript
如果当前位置包含 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
}
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用正则表达式查看 Amaan 答案:
https://stackoverflow.com/a/8619635/887539
See Amaan answer using regexp:
https://stackoverflow.com/a/8619635/887539
演示
Demo
我的建议:
如果该值只需要一次,则不必声明局部变量......
My suggestion:
You don't have to declare local variables if the value are only needed once...