- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 html 页面,其中包含一个在页面加载后即可运行的函数。
<body onload="startNow()">
这个startNow函数有一个部分,如果不满足某个条件,就会刷新页面,从而导致该函数再次运行。
function startNow() {
var warning_check = document.getElementsByClassName("warning");
if (warning_check.length == 0) {
checkAll(); //another function call
} else {
window.location.reload();
}
}
有没有办法让这个 startNow
函数在第一次加载此页面时不运行?
最佳答案
使用本地存储轻松完成
function startNow(){
var warning_check = document.getElementsByClassName("warning");
if(warning_check.length == 0) {
checkAll(); //another function call
} else {
if (!!localStorage.returningUser){
window.location.reload();
}
}
localStorage.returningUser = 'true';
}
编辑
上述函数对于首次使用的用户仍然运行,但如果代码到达重新加载点,它不会重新加载。如果您想让代码完全停止运行,那么
function startNow(){
if (!localStorage.returningUser){
localStorage.returningUser = 'true';
return false;
}
var warning_check = document.getElementsByClassName("warning");
if(warning_check.length == 0) {
checkAll(); //another function call
} else {
window.location.reload();
}
}
关于javascript - 如何使在 onolad 上工作的 JS 函数在第一页加载时不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30112813/
SCENARIO 有两页,第一页是HomePage,它在flutter_bloc软件包的帮助下自动获取api数据。在首页(第一页)中,还有一个按钮,可在此代码Navigator.push(contex
我检查过类似的问题,但由其他人发布,但我仍然看不到我的代码有什么问题。 我刚刚从文档中复制了它 - https://symfony.com/doc/3.4/page_creation.html Luc
我已经编写了一段代码,使用Python中的Scrapy来抓取页面。下面我粘贴了 main.py 代码。但是,每当我运行我的蜘蛛时,它仅从第一页抓取(DEBUG:从抓取),这也是请求中的Referer标
我创建了一个 ios 图书阅读器应用程序。在这个应用程序中,我集成了 google drive 和 skydrive 。现在我可以从 google drive 和 skydrive 登录和检索数据了。
效果图: 功能简介:可使用上下键选中行,选中后点击修改,textbox获得gridview中的代码的数据。对你有帮助的话,请记得要点击“好文要顶”哦!!!不懂的,请留言。废话不多说了,贴码如下
我是一名优秀的程序员,十分优秀!