javascript session variable code example

Example 1: session storage

// Save data to sessionStorage
sessionStorage.setItem('key', 'value');

// Get saved data from sessionStorage
let data = sessionStorage.getItem('key');

// Remove saved data from sessionStorage
sessionStorage.removeItem('key');

// Remove all saved data from sessionStorage
sessionStorage.clear();

Example 2: how to get session value using javascript

sessionStorage.getItem("SessionName")

Example 3: how to use session using javascript

BY LOVE
sessionStorage.setItem("SessionName", "SessionValue");

Example 4: set a value in session using javascript

<script type="text/javascript">
    function GetUserName()
    {

        var username = '<%= Session["UserName"] %>';
        alert(username );
    }
</script>

Example 5: how to get session value using javascript

By LOVE
sessionStorage.getItem("SessionName")

Example 6: set a value in session using javascript

<script type="text/javascript">
function SetUserName()
{
    var userName = "Shahid Bhat";
    '<%Session["UserName"] = "' + userName + '"; %>';
     alert('<%=Session["UserName"] %>');
}
</script>