How to use session in JavaScript?

Tripati_tutu
Posted by Tripati_tutu under JavaScript category on | Points: 40 | Views : 7618
To use session in JavaScript, write
var variableName='<%= Session("Value").ToString() %>'


Here the below code, which you can use as a session in JavaScript under <head> tag, but you can't use this in external JavaScript(.js) files.
<script type="text/javascript" language="javascript">
window.onload = function()
{
var sampleColor = '<%=Session["Color"]%>';
alert(sampleColor);
}
</script>

Comments or Responses

Login to post response