How can I retain the button position of a scroll-able area when pressing back button in Salesforce 1?

Let's say I have more content in VF page which has 2 or 3 pages and a button on a 3rd page on clicking it takes to a new page, (done by using NavigateToUrl) and to come back calling a function

My requirement is to call a visualforce - page2 from page1 and then return back to page1 to specific Div (scroll position)

     function back() {

        if( (typeof sforce != 'undefined') && (sforce != null) ) {
        } else {
            window.location.href = '{!$Page.S1_Back}';

        return false;

Now want to retain my last position (i.e page position where I clicked the button) when the back button is clicked

Updated code - Achieved this through

Setting the Div Id to Local storage in Page 1 then accessing it in Page2

Which works fine in Android Device and S1 Demo but it's not working in IOS devices

<script type="text/javascript">
    function naviToURLPage1() {
            if( (typeof sforce != 'undefined') && (sforce != null) ) {
                // detail or chatter or related
            } else {
                window.location.href = '/apex/S1_Back#'+localStorage.getItem("position");


Not sure if javascript local Storage is supported in IOS devices, Came to know that IOS disables cookies, Is there any workaround for this? check Here

Need to Navigate to specific Div in Salesforce1 from the different page

1 Answer 1


Starting from JavaScript local Storage - Local storage is not the best practice to use in case if you are navigating through pages and this applies to session storage too.

Since the user might use those page in Ios device and in private browsing chances of getting error are more.

since anchor tags are straightforward to use- supported by Android and Chrome and other browsers as you stated before but when it comes to lightning in VF pages, ios browser doesn't scroll as expected.

Best way to pass the id or values is to use URL parameter, pass the values along with URL and then using jQuery or JavaScript get those values and pass it back and vice versa.

//Pass the Id along with page redirection 
window.location.href = '/apex/S1_BackDemo#'+id;

/*And get back the ID after page load or while redirection from the second page
 Do this in both the pages Get from page2 and send it back to pag1 after submitting 
and get in page1 and set it with jQuery animate-ScrollTop*/

 var urlId = location.href.split('#');
  if(urlId != null && urlId.length>1){
      $('html, body').animate({
            scrollTop: $('#'+urlId[1]).offset().top
        },0 );

Above code is to get id form URL and setting the scroll position to a specific div(Original Position) when re-directed again back to page1.

coming to real issue with Ios device on salesforce1 (the issues related to buttons and / or dropdowns that erroneously bring you back to the top of the page when they are clicked) can be solved by

check this thread and use those media screen styles

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .