DarkxPunk Posted November 13, 2012 Share Posted November 13, 2012 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 More sharing options...
justsomeguy Posted November 13, 2012 Share Posted November 13, 2012 There are some pretty good resources here: http://www.html5rocks.com/en/features/storage Link to comment Share on other sites More sharing options...
DarkxPunk Posted November 15, 2012 Author Share Posted November 15, 2012 (edited) 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 November 15, 2012 by DarkxPunk Link to comment Share on other sites More sharing options...
Ingolme Posted November 15, 2012 Share Posted November 15, 2012 You've used an assignment operator in the place of a comparison operator. Link to comment Share on other sites More sharing options...
DarkxPunk Posted November 15, 2012 Author Share Posted November 15, 2012 Ha ha it's working! I am going to expand on this to include more information saved and will post the updated code here.Thanks again. Link to comment Share on other sites More sharing options...
DarkxPunk Posted November 15, 2012 Author Share Posted November 15, 2012 (edited) 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 November 16, 2012 by DarkxPunk Link to comment Share on other sites More sharing options...
DarkxPunk Posted November 17, 2012 Author Share Posted November 17, 2012 No ideas? Link to comment Share on other sites More sharing options...
Ingolme Posted November 17, 2012 Share Posted November 17, 2012 Position? You mean mouse position or something else? Link to comment Share on other sites More sharing options...
DarkxPunk Posted November 17, 2012 Author Share Posted November 17, 2012 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 More sharing options...
Ingolme Posted November 18, 2012 Share Posted November 18, 2012 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 More sharing options...
DarkxPunk Posted November 18, 2012 Author Share Posted November 18, 2012 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 More sharing options...
DarkxPunk Posted November 22, 2012 Author Share Posted November 22, 2012 I can't find anything, no ideas? Link to comment Share on other sites More sharing options...
Ingolme Posted November 22, 2012 Share Posted November 22, 2012 Since it's on the client side, just update the saved scroll data every time the scroll every happens. Link to comment Share on other sites More sharing options...
dsonesuk Posted November 22, 2012 Share Posted November 22, 2012 (edited) 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 November 23, 2012 by dsonesuk Link to comment Share on other sites More sharing options...
DarkxPunk Posted November 23, 2012 Author Share Posted November 23, 2012 Thanks for the help related to the scroll but at the moment my problem is my code not functioning on the iPhone... Link to comment Share on other sites More sharing options...
DarkxPunk Posted November 27, 2012 Author Share Posted November 27, 2012 Guess cookies is my only option. Link to comment Share on other sites More sharing options...
dsonesuk Posted November 27, 2012 Share Posted November 27, 2012 googled iphone localstorage problem, it seems localstorage is stored in cache folder, which can be deleted at anytime, or not stored at all to save space, a lot of forum seem to mention the use of PhoneGap app that uses its own storage system, if thats any help. Link to comment Share on other sites More sharing options...
DarkxPunk Posted November 29, 2012 Author Share Posted November 29, 2012 This just means I need to save it to cookies, thanks anyway. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now