如果窗口.位置以HTML结束,执行javascript
If window.location ends with html execute 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
}
var isHTML = "html" === window.location.pathname.split(".").pop().toLowerCase();
if ( isHTML ) {
//execute javascript here
}
参见Amaan answer using regexp:
https://stackoverflow.com/a/8619635/887539var winloc = window.location.pathname; //for e.g http://mysite.com/home.html
var ishtml = /html$/i.test(winloc); //Remove the i if you want to match only html and not HTML
if(ishtml === true){
//Your JS
}
演示var winloc = window.location; //for e.g http://mysite.com/home.html
var ishtml = winloc.match(/html$/i);
var dothtml = "html";
if(dothtml==ishtml){
//execute javascript here
}
我的建议:
if ( window.location.pathname.match( /html$/ ) ) {
// do it
}
如果值只需要一次,就不必声明局部变量…
var re = /.*('.html)$/i;
var winloc = window.location.href; //for e.g http://mysite.com/home.html
var ishtml = winloc.match(re)[1];
var dothtml = ".html";
if(dothtml==ishtml){
//execute javascript here
alert("yes")
}
相关文章:
- 无法在通过jQuery的ajax加载的页面中执行javascript
- 在Safari执行javascript之前对其进行修改
- 如何在执行此特定onclick事件时执行JavaScript函数
- 如何在从浏览缓存加载页面时执行javascript
- 使用Rhino和ASE执行Javascript的区别
- 如何在加载完整页面后严格执行javascript代码
- 在动态加载的对话框中执行Javascript
- 在Sinatra中执行Javascript
- 通过AJAX加载页面并执行javascript和CSS
- 适用于多种浏览器的Selenium-需要能够执行javascript的webDriver
- 如何在seleniumwebdriver中执行javascript提示并等待接受输入
- 在window.open()生成的窗口中执行JavaScript
- AJAX成功回调-执行javascript时出现问题
- 通过指令在控制器中执行javascript函数
- 从React Native Android原生地执行JavaScript代码
- iframe未执行Javascript方法(PHP)
- 执行JavaScript代码,使用selenium webdriver或WatiN从控制台获取日志
- 通过web驱动程序异步执行Javascript
- 如何在长时间执行JavaScript期间显示微调器
- 点击困难时执行javascript函数