Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent data after refresh

I have a web page that I am having trouble with. It works fine: you select from the drop-down menu and the image updates.

The issue is when the page is manually refreshed: The initial image is displayed but the drop-down menu option stays the same; well, I fixed that.

The real issue is that after the refresh, when I choose a new item, the item before the refresh is displayed for some reason.

How can I change this so the new selection after the refresh is displayed and not the previous one?

My code works fine in Chrome, Firefox, and Safari, but not IE9.

This is the JavaScript code I am using:

function doMillviewInitialise()
{
    window.document.forms[0].reset();
}

And here is the HTML:

<form>
    <select id="millviewStyle" onchange="doMillview();">
        <option value="self">Millview @ Guygar.com&copy;</option>
        <option>----------------------</option>
        <option value="midnightExpress">Midnight Express</option>
        <option value="turnedOn">Turned On</option>
        <option value="storage">Storage</option>
        <option value="plasticStress">Plastic Stress</option>
        <option value="mirrorEffect">Mirror Effect</option>
        <option value="okComputer">OK Computer</option>
        <option value="repertoire">Repertoire</option>
        <option value="calibrate">Calibrate</option>
        <option value="hysteria">Hysteria</option>
        <option value="lastExit">Last Exit</option>
    </select>
</form>
like image 442
iTEgg Avatar asked Aug 30 '11 14:08

iTEgg


People also ask

How do you keep value after page reloading?

To store the form data in JavaScript localStorage, we'll use the setItem() method. It stores the data in the localStorage object and takes the key and value parameters as input. The parameters can be later used to retrieve the data when the browser reloads the page or a new session is initiated.

Does local storage persist on refresh?

The main features of localStorage are: Shared between all tabs and windows from the same origin. The data does not expire. It remains after the browser restart and even OS reboot.

How do I keep my data after refreshing page in HTML?

The easiest way to reload the current page without losing form data, use WebStorage where you have -persistent storage (localStorage) or session-based (sessionStorage) which remains in memory until your web browser is closed. window. onload = function() { var name = localStorage.


1 Answers

iGuygar IE9 has issues with iframes as well as other pretty standard browsers features (the CSS3 text-shadow for example) what you can do is create a div and then position it absolutely about 10000 pixels off the screen then preload your images in the div.

So your div's HTML:

<div id="imgpreload">
 <img src="images/pic1.png" alt="pic1" id="pic1">
 <img src="images/pic2.png" alt="pic2" id="pic2">
 <img src="images/pic3.png" alt="pic3" id="pic3">
</div>

The CSS:

#imgpreload {
  position:absolute;
  left:9999px; 
}

some like to also add (unnecessarily, except for mobile customers):

width:1px;
height:1px;
overflow:hidden;

to that CSS. This will preload your images in all known browsers.

like image 90
Serj Sagan Avatar answered Oct 12 '22 00:10

Serj Sagan