How to pass variable value between different html pages in javascript

前端 未结 5 2033
滥情空心
滥情空心 2020-11-27 17:45

I want to pass the value of selected list item to the other page,means if I m selecting abc from the list then this abc value passes to the next html form a

5条回答
  •  臣服心动
    2020-11-27 18:16

    There are different ways to do it

    Store the selected item in the cookies

     // Store it in the cookies
     document.cookie="selected=john"
    
    // Get it in the profile.html
    var cookie = document.cookie;
    

    Store the selected item in the local storage

    // Store it in the local storage
    localStorage.setItem('selected', 'john');
    
    // Get it from the local storage
    var selected = localStorage.getItem('selected');
    

    Use query parameter(Recommended)

    You can pass the selected item in query parameter of profile.html?selected=john. I recommend this method. You can read the selected item by location.search

提交回复
热议问题