0

I am working on javascript as well as jquery. and i am using 2divs in my page. so when my page loads the second div is hidden and when a button from the first div is clicked it navigates to the second page. so when i press refresh button now. the page navigates to the first div as it reacts when the page is opened for the first time. any ideas or suggestions to make the second div display even when the page is refreshed. thanks in advance. here is my fiddled code it works fine in the fiddle as i exactly want. but it fails in my project code. http://jsfiddle.net/pWryf/ . any example to attain this through cookies.?

Here is my code for the div:

$('#sbut1').click(function() { 
    $('.cont1').show();
    $('#log1').hide();
});
Hk M
  • 73
  • 2
  • 10

2 Answers2

0

I can think of atleast 2 frontend approaches to this problem:

  1. using a cookie or a more modern localstorage solution to handle sessions. (already been here, cookie)

  2. using a one page app, where navigations is after the hash # sign. such as in backbone webapps.

You can also use some kind of server side session handling, most web framework have one embedded.

alonisser
  • 11,542
  • 21
  • 85
  • 139
0

Try something like this using localStorage:

$('#sbut1').click(function() { 
    $('.cont1').show();
    $('#log1').hide();
    localStorage['shown'] = '.cont1';
});

$(function() {
    var sel;
    if (sel = localStorage['shown']) {
        $('.cont1, #log1').hide().filter(sel).show();
    }
});

http://jsfiddle.net/5aJZR/

Use can also use cookies for this purpose.

dfsq
  • 191,768
  • 25
  • 236
  • 258
  • it works fine in the fiddle as i exactlywant. but it fails in my project code. Any suggestions.? – Hk M Jun 26 '13 at 05:58
  • it works fine in the fiddle as i exactlywant. but it fails in my project code. Any suggestions.? here is my fiddled code http://jsfiddle.net/pWryf/ . – Hk M Jun 26 '13 at 06:13
  • i found out a way as it worked fine with sessionStorage. Thank you – Hk M Jul 02 '13 at 10:44