1

If i use the following code below, it works perfectly on firefox (private window or normal window). I tried to use it on my iphone 6 using safari and it doesnt seem to store my information in normal mode (non private mode)? Maybe the code is not right for safari? Can someone assist me? Thanks!

Code:

<script>
// Run on page load
window.onload = function() 
{
    // If sessionStorage is storing default values (ex. name), exit the function and do not restore data
    if (sessionStorage.getItem('name') == "name") 
    {
        return;
    }

    // If values are not blank, restore them to the fields
    var name = sessionStorage.getItem('name');
    if (name !== null) $('#playlisthiddenfield').val(name);
}

// Before refreshing the page, save the form data to sessionStorage
window.onbeforeunload = function() 
{
    sessionStorage.setItem("name", $('#playlisthiddenfield').val());
}
</script>

Basically the issue is, once i refresh the information in the input field disappears where as in firefox it stays (Which i want it to).

William
  • 1,009
  • 15
  • 41
  • 1
    If it is simple text, why not use a cookie? [https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/cookies/set](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/cookies/set). Cookies are compatible with pretty much everything: [http://caniuse.com/#search=cookies](http://caniuse.com/#search=cookies) – Emil S. Jørgensen Oct 12 '16 at 11:04
  • This might help: http://stackoverflow.com/questions/14555347/html5-localstorage-error-with-safari-quota-exceeded-err-dom-exception-22-an – Rajesh Oct 12 '16 at 11:05
  • @EmilS.Jørgensen thank you! I just did that there now and works perfectly.. Dont know why i just didnt use that xD – William Oct 12 '16 at 11:32
  • 1
    @irishwill200 Glad to be of service :). Please note that there is a serious memory difference though. Cookies has a max-size of about 4Kb while localStorage has several Mb of storage. – Emil S. Jørgensen Oct 12 '16 at 11:39

1 Answers1

1

I dont exactly have the answer to the question but instead i decided to use cookies to complete this task and i am only storing a value which i can access with an if statement so no personal information is stored.

William
  • 1,009
  • 15
  • 41