weeraa
weeraa

Reputation: 1195

Keep session effecting for few browser tabs

I'm doing web project using Jquery, Html and node js web server. I'v read few articles about browser storage. There are 2 kind of storage as localStorage and sessionstorage. localstorage keeps data till clear it and sessionstorage will erase after closing the browser. I used sessionstorage for my project, because I don't want to keep data after closing the browser.

For write data to session

sessionStorage.setItem('usersession', response.session);

For get data from session

var usrSess = sessionStorage.getItem('usersession');

What my question is, I copy and paste the URL to new tab in the browser(It means duplicate the current web page to new tab). But those sessions are not there. (sessions are null) So what is the best way to keep session for new tabs also? I dont want to use localstorage, because if I close the browser, it keeps data in browser storage.

Try 1

I try to use jquery cookie sessions. Downloaded js.cookie.js file from the internet and use like below.

Login html is defined js files.

 <script src="./plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <script src="./bootstrap/js/jquery.cookie.js"></script>    
    <script src="./scripts/user.js"></script>

for testing purpose, I hard-code a cookie in document.ready function in user.js file

$(document).ready(function () {   
    $.cookie("sampleCookie", "TestValue001");

    //other code going here 
});

It is occurred error Uncaught TypeError: $.cookie is not a function. Hope I used the correct hierarchy of defining js files.

These are the sites that I downloaded cookie.js

https://plugins.jquery.com/cookie/ https://github.com/js-cookie/js-cookie

Then I used a CDN location also.

<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script> 

Still there is "cookie is not a function" issue and unable to find a solution :(

Upvotes: 0

Views: 269

Answers (0)

Related Questions