sessionStorage displays undefined in IE11?

Nov 19 2016 3:08 AM

I am working on web related applications.When i try to display sessionStorage item it returns "undefined".

IE settings also changed but still i am getting same.

 

Login.html page:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
var currentDate = new Date,
dformat = [(currentDate.getMonth() + 1),
currentDate.getDate(),
currentDate.getFullYear()].join('/') +
' ' +
[currentDate.getHours(),
currentDate.getMinutes(),
currentDate.getSeconds()].join(':');
function unicsession(length) {
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz";
var sess = "";
for (var x = 0; x < length; x++) {
var i = Math.floor(Math.random() * chars.length);
sess += chars.charAt(i);
}
return sess;
}
function generate() {
var intime = dformat;
sessionStorage.setItem("logintime", intime);
var username = document.getElementById("Username").value;
sessionStorage.setItem("username", username);
var unisession = unicsession(5);
sessionStorage.setItem("unisession", unisession);
}
</script>
</head>
<body>
<table>
<tr>
<td>
<input id="Username" type="text" />
</td>
</tr>
<tr>
<td>
<a href="home.htm" onclick="generate()">Click here</a>
</td>
</tr>
</table>
</body>
</html>

home.htm page code:

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title></title>

<script type="text/javascript">

var getid = sessionStorage.getItem("username");

var logintimes = sessionStorage.getItem("logintime");

var unicsessionid = sessionStorage.getItem("unisession");

var currentDate = new Date,

outformat = [(currentDate.getMonth() + 1),

currentDate.getDate(),

currentDate.getFullYear()].join('/') +

' ' +

[currentDate.getHours(),

currentDate.getMinutes(),

currentDate.getSeconds()].join(':');

function Getout() {

alert("Login Id: " + getid + " ; login Time: " + logintimes+" ; Unic Session-Id : "+unicsessionid+" ; Logout Time : "+outformat);

}

</script>

</head>

<body>

<input id="logout" type="button" value="Logout" onclick="Getout()"/>

</body>

</html>

When i click on login page it redirect to home page and after click on logout button in home page it displays undefined.

How can i resolve this issue.

Thanks in advance for help.


Attachment: loginlogout.zip

Answers (1)