我正在使用本地存储来在页面之间传递值,以创建滚动效果(用户点击链接后根据ID被滚动到页面的特定部分)。
我之前使用的是cookie,但在Android上似乎不起作用,我读到本地存储得到支持,所以切换到了它。在浏览器中完全正常,但一旦打包成原生应用程序,我就失去了所有功能?API说明应该支持它,有什么想法吗?
这是我的代码:
基本URL:
我之前使用的是cookie,但在Android上似乎不起作用,我读到本地存储得到支持,所以切换到了它。在浏览器中完全正常,但一旦打包成原生应用程序,我就失去了所有功能?API说明应该支持它,有什么想法吗?
这是我的代码:
基本URL:
var storage = window.localStorage;
$("a.scroll_link").click(function(event) {
event.preventDefault();
var value = $(this).attr("id");
storage.setItem("key",value);
console.log(value);
window.location=$(this).attr("href");
});
接收URL:
$(function () {
var value = window.localStorage.getItem("key");
if (value != "" && value != "undefined" && value != null) {
var storage = window.localStorage;
storage.setItem("key",value);
var scroll_type = "";
if ($.browser.webkit) {
scroll_type = "body";
} else {
scroll_type = "html";
}
$(scroll_type)
.stop()
.animate({
//get top-position of target-element and set it as scroll target
scrollTop: ($("#" + value).offset().top - 25)
//scrolldelay: 1.5 seconds
}, {
duration: 1500,
complete: function () {
storage.removeItem("key");
},
});
}
});
这段代码在浏览器中运行良好,但本地运行时却出现了问题,有什么想法吗?
谢谢。