I use Local Storage to pass values between pages to create a scroll for the effect (link to user clicks and scroll to a specific part of the page based on the id)
I used cookies before, but didn’t seem to work on Android, I read that local storage is supported so that it switches to it. It works fine in the browser, but as soon as it is packaged as a native application, do I lose all functionality? The API claims that it should be supported, any ideas?
Here is my code:
Base 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");
});
Receiving 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({
scrollTop: ($("#" + value).offset().top - 25)
}, {
duration: 1500,
complete: function () {
storage.removeItem("key");
},
});
}
});
The code doesn’t work fine in the browser initially, any ideas?
Thank,
source
share