[英]Store hash information for drop-down selection
我猜想我需要为此做一个cookie,但是请告诉我是否还有其他方法。 我有一个下拉菜单,该菜单使用链接元素在网站上选择一种语言,具体取决于他们选择的链接元素,然后在URL末尾附加一个哈希。 我正在寻找一种存储此选择的方法,以使选择保留在所有页面上,而不是每次刷新或离开页面时都将其重置。
这是HTML:
<div class="menu cid">
<a href="#" title="en">United States</a>
<a href="#" title="can">Canada</a>
</div>
和脚本:
$(document).ready(function(){
if(document.location.hash == ""){
location.href = location.href + "#en";
}
});
jQuery('.menu a').on('click', function(event) {
event.preventDefault();
var clickedAnchor = jQuery(this),
countryID = clickedAnchor.attr('title');
location.href = location.href.split('#')[0] + '#' + countryID;
location.reload();
});
var countryID = window.location.hash;
countryID = countryID.substring(1);
console.log("country code: "+countryID);
var countryID = "en";
if (document.location.hash != "") {
countryID = document.location.hash.substring(1);
}
var map = {"en":"4242", "can":"4243"};
cii_EmbedProductLinks('Chairs','{{ prodID }}',map[countryID], CI_LinkID);
谢谢!
可能的解决方案是
我讨厌人们只粘贴链接,但是现在我只能这样做:
https://developer.mozilla.org/zh-CN/docs/Web/Guide/API/DOM/Storage#localStorage
抱歉,希望对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.