[英]How to create an onclick cookie link and then after navigating to link's url, have that cookie redirect the current url
Okay, so this may sound confusing, so let me explain. 好的,这听起来可能令人困惑,所以让我解释一下。 I'm working with a theme in wordpress that has a single page layout and standalone page layouts.
我正在使用一个具有单个页面布局和独立页面布局的wordpress主题。 In the single page layout, every navbar link you click on scrolls you to a section of the page.
在单页面布局中,您单击的每个导航栏链接都将您滚动到页面的一部分。 In the standalone pages, when you click on a navbar link that contains content for the home page, it links you to a standalone page of that content rather than going to the home page and scrolling to the content.
在独立页面中,单击包含主页内容的导航栏链接时,它会将您链接到该内容的独立页面,而不是转到主页并滚动到该内容。
Now before I get many answers saying just do url/#content block, it doesn't work as the theme creator decided to use multiple ids all named content. 现在,在我得到很多答案之前,说只是做url /#content块,这是行不通的,因为主题创建者决定对所有命名的内容使用多个ID。 Horrible I know.
我知道这太可怕了。 I've tried a lot of things actually.
我实际上已经尝试了很多东西。 So the idea I have now, is to store a cookie when the user clicks a link in the #header navbar and store a cookie in the browser.
因此,我现在的想法是在用户单击#header导航栏中的链接时存储cookie,并在浏览器中存储cookie。 When the user reaches the homepage, the homepage checks that cookie and scrolls the to the proper area.
当用户到达主页时,主页会检查该cookie并将其滚动到适当的区域。
I've never worked with cookies to know how to write the code, I just understand how they work from php, I figure javascript is somewhat similar. 我从来没有使用过cookie来了解如何编写代码,我只是了解它们如何从php中工作,我认为javascript有点相似。 If something is unclear, please ask.
如果不清楚,请询问。
You have 2 types of cookies, Http only and regular (you have more, but for this question the others are non relevant). 您有两种类型的cookie,仅Http和常规的cookie(您有更多类型,但是对于这个问题,其他类型都不相关)。 Since here you are talking about creating cookies in JavaScript, the Http only cookies are non existent.
因为这里是在谈论用JavaScript创建cookie,所以不存在仅使用Http的cookie。
This javascript basic library will give you the tools to do what you want. 此javascript基本库将为您提供执行所需功能的工具。
Now, from my own view of this problem, I would recommend using local storage only if your viewers are using new browsers (old IE won't work). 现在,从我自己对这个问题的观点来看,我建议仅在您的查看器使用新浏览器的情况下才使用本地存储(旧的IE无法使用)。 This javascript library will explain how to use it.
这个javascript库将说明如何使用它。
Hope I helped, Cheers! 希望我能帮助,干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.