JavaScript Session storage variable on another page

后端 未结 3 582
日久生厌
日久生厌 2020-12-02 01:42

So I\'m rather new to JavaScript and I would love some help getting this code to work. I\'ve looked at multiple other posts talking about session storage as well as if/else

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 01:59

    Edit: Clearly the answer above is much better than what i provided. I'll leave this here for future viewers - maybe the way I phrased things help someone sometime.


    Taylor,

    Two things.

    1. sessionStorage() is unique to each page/tab. From the docs "Opening a page in a new tab or window will cause a new session to be initiated"

    2. window.onload is expecting a function. You're just concatenating a string.

    If you find a different way to pass information from one page to another (you could stuff it in the URL) your new color function should look something like this:

    
    

提交回复
热议问题