Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Base on <a href="https://stackoverflow.com/users/15498/damien-the-unbeliever">Damien_The_Unbeliever</a> comment I create this answer post for my own question.</p> <p>This is final working solution that I use.</p> <p><strong>[Update #3]</strong></p> <p>Tested on: </p> <ul> <li>FF 16.0.1 --> Working! </li> <li>IE 8 --> Working!</li> <li>Chrome 24 --> Working! (Note: this browser need a little extra effort to make it can read cookie. see this <a href="http://www.techtoolblog.com/archives/subdomain-cookies-and-localhost" rel="nofollow noreferrer">link</a>)</li> </ul> <p>Basically the code is still same as Update #2, the different is I use cookie instead of <code>sessionStorage</code>. Here is the complete code:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i &lt; ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); } function switchImage() { var images = []; images[0] = "I_am_Super_Magnet%21.jpg"; images[1] = "World_In_My_Hand%21.jpg"; var index = readCookie('index'); //sessionStorage.getItem('index'); if(index == null) index = 0;//set index to zero if null index = parseInt(index);// parse index to integer, because sessionStorage.getItem() return string data type. if(index == 0) { document.getElementById("locationA").src=images[index]; document.getElementById("locationB").src=images[index+1]; index = index + 1; } else if(index == 1) { document.getElementById("locationA").src=images[index]; document.getElementById("locationB").src=images[index-1]; index = index - 1; } createCookie('index', index); //sessionStorage.setItem('index', index); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="switchImage()"&gt; &lt;img id='locationA' src='src_locationA'&gt; &lt;img id='locationB' src='src_locationB'&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload