I have some problem with the stateless nature of .NET MVC framework.
I have some HTML like
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
<button id="btnShowMore">Show More</button>
<a href="www.google.com">Google</a>
and my javascript goes like
var maxDisplay = 5;
var unit = 5;
$("li").slice(maxDisplay).hide();
if ($("li").length <= maxDisplay) $('#btnShowMore').hide();
$('#btnShowMore').click(function () {
maxDisplay += unit;
$("li").slice(0, maxDisplay - 1).show();
if ($("li").length <= maxDisplay) $('#btnShowMore').hide();
});
Now if I expand my list, navigate to google, and click back button in my browser, the list would forget what I did and shows only the first 5 list item, which is not what I want.
I thought of some options:
cookie. not quite what I want because there are lots of pages like this, and I would need cookie for each of them
manipulate url a bit, like taking advantage of window.location.hash. also not good, because that would be another page
Is there some conventional way to do this?
Thanks in advance
UPDATE:
seems like no more solutions coming out. I'd definitely prefer localStorage over cookie as there's no need to transfer this variable between client and server, but there needs a check whether the page is first load (clear cached variable and show 5 items) or load from navigate back(read cache and show cached number of items).
maybe I should go with hash...