如何在页面重新加载后跟踪哪些按钮被按下? [英] How to keep track of which buttons have been pressed after page reloaded?

查看:93
本文介绍了如何在页面重新加载后跟踪哪些按钮被按下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Javascript和JQuery的新手。在搜索互联网寻求解决方案后,我决定发布这个问题。

I'm new to Javascript, and JQuery. After searching the internet for solutions, I decided to post this question.

问题:当用户点击iframe中的链接时,它会更新父级的进度条,只会触发一次。但是,当用户转到另一个页面并返回时,iframe中的页面将被重新加载,javascript也是如此,这意味着可以再次更新该按钮的进度条,这是我不想要的。在重新加载和禁用该功能后,有没有办法跟踪哪些元素被点击? URL-Parameters ??

The problem: When the user clicks on a link within the iframe, it updates the progressbar on the parent, which is only triggered once. BUT, when the user goes to another page, and comes back, the page in the iframe is reloaded, and so is the javascript, meaning that the progressbar can be updated again for that button, which I don't want. Is there any way of keeping track of which elements are clicked, after reload and disabling that function? URL-Parameters??

iframe中的HTML:

HTML in iframe:

<div id="sidenav">
   <ul>
      <li><a href="../right/section1/page1.html" target="presentation" class="active" name="position">positioning</a></li> 
      <li><a href="../right/section1/page2.html" target="presentation">comparisons</a></li>
    </ul>
</div>

iframe页面中的Javascript:

Javascript in iframe page:

$('#sidenav ul li a').one('click', window.parent.updateBar);


推荐答案

类似 localStorage 。唯一的缺点是,即使重新启动后它仍然是持久的,但如果重新加载完整的网站,您可以重置该值。 IE7及更低版本也不支持它。

Something like localStorage. The only drawback is that it is persistent even after rebooting etc, but you can reset the value if your complete website is reloaded. Also it's not supported by IE7 and lower.

function updateBar() {
    if(localStorage['pressed'] == 'true') return; // abort if already pressed

    // do things

    localStorage['pressed'] = 'true'; // save the data that it is pressed
}

这篇关于如何在页面重新加载后跟踪哪些按钮被按下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆