如果URL包含字符串don't运行jQuery函数
If URL contains string don't run jQuery function?
我有一个jquery,它可以运行并重新加载我网站上的所有页面。问题是,我更希望脚本不重新加载某些页面。
例如:若url包含"字符串-1"和/或"字符串-2",则不要重新加载页面。(例如,字符串是文件夹/blog/)。这可能吗?感谢
$(function(){
$('body').fadeIn(1000);
if (localStorage.reloaded !== 'true') {
setTimeout(function(){
$('body').fadeOut(2000, function(){
localStorage.reloaded = 'true';
location.reload(true);
});
}, 5000); // 5 seconds for demo
}
});
您可以使用indexOf()
检查另一个字符串中是否存在一个字符串。试试这个:
var loc = window.location.href;
if (localStorage.reloaded !== 'true' && (loc.indexOf('string-1') != -1 || loc.indexOf('string-2') != -1)) {
setTimeout(function(){
$('body').fadeOut(2000, function(){
localStorage.reloaded = 'true';
location.reload(true);
});
}, 5000); // 5 seconds for demo
}
试试这个。。。。。。
$(function(){
if(window.location.href.indexOf("string-1")!=-1)
{
$('body').fadeIn(1000);
if (localStorage.reloaded !== 'true') {
setTimeout(function(){
$('body').fadeOut(2000, function(){
localStorage.reloaded = 'true';
location.reload(true);
});
}, 5000); // 5 seconds for demo
}
}
});
$(document).ready(function() {
if (window.location.href.indexOf("string-1") > -1 || window.location.href.indexOf("string-2") > -1) {
$('body').fadeIn(1000);
if (localStorage.reloaded !== 'true') {
setTimeout(function() {
$('body').fadeOut(2000, function() {
localStorage.reloaded = 'true';
location.reload(true);
});
}, 5000); // 5 seconds for demo
}
}
});
这应该工作
相关文章:
- 对动态创建的元素运行jQuery.ech()
- 如何在加载角度函数后运行jQuery代码
- 在AJAX jQuery加载()之后运行jQuery代码
- 如何仅在设备基于 iOS 时运行 jQuery 代码
- 使用 .on 函数运行 jQuery 声明函数
- html代码没有运行jquery问题
- 仅在尚未运行jQuery UI的情况下运行动画
- 在运行jquery之前从5开始倒计时
- 在不重新运行jquery验证的情况下检查表单是否有效
- 在Angular App中运行jQuery函数
- 一旦设置了PHP查询字符串,如何运行jQuery脚本
- 如何在Ember中更改模板时运行JQuery代码
- 如果URL包含字符串don't运行jQuery函数
- 在php之前运行jQuery脚本
- 无法动态地将 jquery 添加到头部并运行 jquery 代码
- 在 HTML 中运行 jquery 脚本
- 如何在控制器外部和视图内在 AngularJs 中运行 jQuery
- 在具有相同类的每个表上运行 jquery
- 在 Angular 完成渲染后运行 JQuery 代码
- 如何选择当前 DIV ID 以使用该 ID 运行 Jquery