The session Storage, stores the data for one session.
The data is deleted when the user closes the browser window.
create and access a session Storage
Syntax:
<script type="text/javascript">
sessionStorage.name="My name is sessonStorage";
document.write(sessionStorage.name);
</script>
Example:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
sessionStorage.name="My name is sessonStorage";
document.write(sessionStorage.name);
</script>
</body>
</html>
count the number of times the user has visited in the current page session.
Syntax:
<script type="text/javascript">
if (sessionStorage.pagecount)
{
sessionStorage.pagecount=Number(sessionStorage.pagecount) +1;
}
else
{
sessionStorage.pagecount=1;
}
document.write("Visits "+sessionStorage.pagecount+" time(s) this session.");
</script>
Example:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
if (sessionStorage.pagecount)
{
sessionStorage.pagecount=Number(sessionStorage.pagecount) +1;
}
else
{
sessionStorage.pagecount=1;
}
document.write("Visits " + sessionStorage.pagecount + " time(s) this session.");
</script>
<p>Refresh the page to see the counter increase.</p>
<p>Close the browser window, and try again, and the counter has been reset.</p>
</body>
</html>
The data is deleted when the user closes the browser window.
create and access a session Storage
Syntax:
<script type="text/javascript">
sessionStorage.name="My name is sessonStorage";
document.write(sessionStorage.name);
</script>
Example:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
sessionStorage.name="My name is sessonStorage";
document.write(sessionStorage.name);
</script>
</body>
</html>
count the number of times the user has visited in the current page session.
Syntax:
<script type="text/javascript">
if (sessionStorage.pagecount)
{
sessionStorage.pagecount=Number(sessionStorage.pagecount) +1;
}
else
{
sessionStorage.pagecount=1;
}
document.write("Visits "+sessionStorage.pagecount+" time(s) this session.");
</script>
Example:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
if (sessionStorage.pagecount)
{
sessionStorage.pagecount=Number(sessionStorage.pagecount) +1;
}
else
{
sessionStorage.pagecount=1;
}
document.write("Visits " + sessionStorage.pagecount + " time(s) this session.");
</script>
<p>Refresh the page to see the counter increase.</p>
<p>Close the browser window, and try again, and the counter has been reset.</p>
</body>
</html>
No comments:
Post a Comment