Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

scroll position at the same after another page loaded

I want to get scroll position at same when the user clicks any menu of navigation bar. When menu is clicked the window is refreshed! I think this is different than window refresh.

How could I get the scroll position at same when window is refreshed?


My site implement is likely to this http://jsfiddle.net/JUKBP/1/ and my scroll position is at something mid that is green div hidden condition

Upvotes: 0

Views: 995

Answers (2)

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28548

try:

  function onAjaxCall(){  
    scrollTop=$(document).scrollTop();        
    $.ajax({
    type: "POST",
    url: url,
    data: data,
    success: function(data){
      //action with data
      $(document).scrollTop(scrollTop);
    },
    dataType: dataType
    });
  }

Upvotes: 0

Mujah Maskey
Mujah Maskey

Reputation: 8804

you can do like this. (javascript solution).

Note: I am using https://github.com/carhartl/jquery-cookie for cookie

get Window ScrollTop value (you can use jQuery for easy). eg: $(window).scrollTop() Save value on cookie. eg:

$(window).unload(function() {
  var top = $(window).scrollTop();
  $.cookie('widowtop', top);
});

you can read that value from cookie, where you want to scroll page at beginning. and use jQuery (for easy) to set window scroll at document.ready event.

eg: on your document

$(function(){
    var top = $.cookie('widowtop');
    $(window).scrollTop(top);
});

Upvotes: 2

Related Questions