Jump to content

Web App: Workaround page from loading home page


DarkxPunk

Recommended Posts

Hey everyone, So I have been researching this extensively and I cannot find an answer. Now can you peoples? Simply what happens is every time you open a web app on iOS it loads the page your created it from, now thats really annoying when you have a multipage web app and you do not want your users to lose their place (or information, but we will get at that after we solve the first problem). I have some places for myself and everyone else assisting to start and that is the fact that iOS uses HTML5 and Web Storage, great! That means we can save stuff for the users visiting the site (for example the last page they were on?). Now you may tell me, "Hey you found the solution" well I have no idea how to call it. I will try and understand but any help is appreciated. Thanks!

Link to comment
Share on other sites

Here is my test code:

var currentPage = location.href; if (currentPage != 'beta.ormt.ca' && localStorage.getItem('lastPage') != null){localStorage.setItem('lastPage',currentPage);}if (currentPage = 'beta.ormt.ca' && localStorage.getItem('lastPage') != null){location.href = localStorage.getItem('lastPage');}

Now this happens on load. What I don't understand is when I load the page it just started refreshing like mad. I don't understand why... Any ideas? (I just had one but too late to test... Is the lastPage key not keeping the resulting string, but rather the variable currentPage? If so how would I get around that?)Thanks for any help!

Edited by DarkxPunk
Link to comment
Share on other sites

I am trying to come up with a concept to save the last position on the page, the problem is that iOS does not support unload when closing a web app.Ideas how to get around it? Do a loop constantly saving the y maybe?Well it's not working on the iPhone, but works fine on my iPad... Why?

Edited by DarkxPunk
Link to comment
Share on other sites

Well first and foremost I need to get my script to work on the iPhone... I can only get it functioning on the iPad. In regards to position I mean the Y scroll position. Please note this thread is simply about mobile web apps for iOS. Not desktops, IDC about desktops.

Link to comment
Share on other sites

You can make an AJAX request each time the user stops scrolling remembering the last scroll position rather than wait for an unload event. Where you store it depends on how long you want this volatile information to last.

Link to comment
Share on other sites

That would be a workaround from localStorage, and I could also use cookies. Though I rather figure out why localStorage is not working. Also how would I detect when a scroll stops... I can only find when a scroll is going on... Thanks for any help. I will continue researching and update if I find anything.

Link to comment
Share on other sites

This seems to work, try this for experiment, yes it uses jquery

$(document).ready(function(){  //on page load retrieve storage value if anyif(typeof(Storage)!=="undefined")  {  document.getElementById("status").innerHTML="Current Y coordinates: " + localStorage.Y_page1_coords;  }else  {  document.getElementById("status").innerHTML="Sorry, your browser does not support web storage...";  }  }); $(document).scroll(function(e){// on scrolling of page store y coordinatesif(typeof(Storage)!=="undefined")  {  localStorage.Y_page1_coords=$(window).scrollTop();// use different storage for different pages ie  Y_page1_coords, Y_page2_coords, Y_page3_coords etc  document.getElementById("status").innerHTML="Current Y coordinates: " + localStorage.Y_page1_coords; //for test show in fixed element with id status  }else  {  document.getElementById("status").innerHTML="Sorry, your browser does not support web storage...";  }   });

<p id="status"></p>

#status {position: fixed; top:0; left:0;}

it showed value returned from localstorage when page was closed and reopen, leave to another page then return, in both cases the value remained the same.

Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...