[英]Check for window.location.href.indexOf doesn't work
仅当用户所在的当前页面是“ Create
页面或“ Edit
页面时,我才尝试每秒在服务器上调用一个页面。 但是此代码不起作用:
function sessionRefresh(){
var remoteURL = '/path/to/file';
$.get(remoteURL, function(data){
setTimeout('sessionRefresh()',1000);
});
}
if(window.location.href.indexOf("/create" != -1) || window.location.href.indexOf("/edit" != -1)) {
setTimeout('sessionRefresh()',1000);
}
sessionRefresh()函数正在所有页面上运行。 但是我只希望它在URL中包含/create
或/edit
的情况下运行。 请注意,我不会每秒在生产服务器上获取此文件。 它仅用于测试。
我该如何重写它,以便仅在那些创建和编辑页面上调用该函数?
您输入了复制粘贴的错字,请尝试
if(window.location.href.indexOf("/create") != -1 || window.location.href.indexOf("/edit") != -1) {
代替
if(window.location.href.indexOf("/create" != -1) || window.location.href.indexOf("/edit" != -1)) {
更换
if(window.location.href.indexOf("/create" != -1) || window.location.href.indexOf("/edit" != -1)) {
setTimeout('sessionRefresh()',1000);
}
同
if(window.location.href.indexOf(“ / create”)!= -1 || window.location.href.indexOf(“ / edit”)!= -1){setTimeout('sessionRefresh()',1000) ; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.