简体   繁体   English

记住在更改页面之前单击

[英]Remember click before changing pages

Is there a way to remember the click that transitions to a new page using jquery. 有没有一种方法可以记住使用jquery转换到新页面的点击。 I have a page where a tree drop down structure transitions to a new page. 我有一个页面,其中树状下拉菜单结构过渡到新页面。 If the user comes back to previous page, i'd like to have the tree expanded as it was before. 如果用户返回上一页,我想像以前一样扩展树。 The page from which it happens uses a .live('click') function. 发生该事件的页面使用.live('click')函数。 I don't have any code that I did so can't paste anything here. 我没有执行的任何代码,因此无法在此处粘贴任何内容。 Just looking out for suggestions or hints! 只是寻找建议或提示! :) :)

Use cookies . 使用Cookie When the tree is expanded, store it: 展开树后,将其存储:

document.cookie = "tree=open";

When the user visits the page, check for it: 当用户访问该页面时,请检查该页面:

if (document.cookie.search(/tree-open/) != -1) {
    ...
}

My code is over-simplified to help you look in the right direction. 我的代码过分简化,以帮助您朝正确的方向看。 You may want to borrow a JS cookie library. 您可能想借用JS cookie库。

If your application is in HTML5 then you can use HTML5 Web Storage and save the clicked link in it and on load check if some link was clicked then open that else open the first link, you can check it in jquery easily. 如果您的应用程序使用HTML5,则可以使用HTML5 Web存储并将单击的链接保存在其中,并在加载时检查是否单击了某些链接,然后打开该链接,否则打开第一个链接,则可以在jquery中轻松对其进行检查。

thanks abhishek 谢谢abhishek

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM