Javascript and session variables

前端 未结 5 1393
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-21 08:28

I have a database that stores events in it and a page with a calendar object on it. When rendering the days it looks through the months events and if any match the current d

相关标签:
5条回答
  • 2020-12-21 08:43

    Add another query string variable that the page can use to trigger existing vs new.

    0 讨论(0)
  • 2020-12-21 08:45

    If you are using something like Struts2, you can have a hidden variable in your jsp

    <s:hidden id="EditModeId" value="%{#session.EditMode}"/> 
    

    And within javascript simply access this variable

    alert(document.getElementById('EditModeId').value);
    
    0 讨论(0)
  • 2020-12-21 08:56
    var page1 = document.getElementById("textbox").value; 
    sessionStorage.setItem("page1content", page1);
    

    in other page use this value as like session variable

    document.getElementById("textbox2").value=sessionStorage.getItem("page1content");
    
    0 讨论(0)
  • 2020-12-21 09:06

    Your session vars are controlled by the server, JS runs client side, and as such cannot modify the vars directly.

    You need to make server requests using POST or GET and hidden iframes, or XMLHTTPRequest() calls to send data from the JS to the server, and then have your server side code handle the vars.

    Add another query string variable that the page can use to trigger existing vs new.

    0 讨论(0)
  • 2020-12-21 09:06

    You definitely need to add a variable to the target page. But I take it that you are doing a popup scenario, so you should be able to create a javascript function OpenWindow() and fire it off when the user clicks the link.

    <script>
    function OpenWindow(eventId, editMode)
    {
        var window = window.open("popup.aspx?eventId=" + eventId + "&editMode=" + editMode);
    }
    </script>
    

    On the server side you need to build the call to the OpenWindow function. For example:

    onclick="OpenWindow(eventId=" + row["eventId"].ToString() + "&editMode=" + editMode.ToString() + ");"
    

    So in other words, prep everything on the serverside to set your javascript to post all variables to the new page. Hope this helps.

    0 讨论(0)
提交回复
热议问题