Call local storage methods such as localstorge and cookies
Method 1: Use localstorage
Use localstorage. setitem (Key, value); to add content
Monitor adding, modifying, and deleting actions using storage events
Window. addeventlistener ("Storage", function (event ){
$ ("# Name"). Val (event. Key + "=" + event. newvalue );
});
Method 2: Use cookie + setinterval
<Inputidinputid = "name"> <input type = "button" id = "btnok" value = "send">
$ (Function (){
$ ("# Btnok"). Click (function (){
Varname = $ ("# name"). Val ();
Document. Cookie = "name =" + name;
});
});
// Obtain the cookie day content
Function getkey (key ){
Return JSON. parse ("{\" "+ document. cookie. replace (/; \ s +/Gim ,"\",\""). replace (// Gim, "\": \ "") + "\"} ") [Key];
}
// Obtain the cookie content every one second
Setinterval (function (){
Console. Log (getkey ("name "));
},1000 );
How can we implement communication between multiple tabs in the browser?