Open several pages in the same browser.cookieTherefore, assume that the page for selecting a song is a page, and the page for music box is B page. When you click the play button on page A, write a cookie and set a timer on page B, continue to check whether the cookie has changed, and then proceed with further processing.
UsecookieIt's still quite troublesome. Another thing that will also be shared isStorageAnd it hasonstorageMethod listeningStorageThat is much more convenient. Write a simple example. The target is to click the button on page A. If page B is not opened, page B is opened and data is accepted. If page B is already opened, data is accepted directly. BelowPage BAcceptPageUploadedIDThe value isNew, UseIsloginJudgmentPage BWhether it is enabled.
A.html
VaR id = 0; // For convenience, use a variable to record var flag = false; BTN. onclick = function () {ID ++; additem () ;}function additem () {var islogin = localstorage. getitem ('islogin'); If (islogin) {localstorage. setitem ('new', ID);} else {window. open ('. /B .html '); flag = true;} window. addeventlistener ('store', function (e) {If (flag & E. key = 'islogin') {flag = false; additem () ;}, false );
B .html
// Add the record localstorage when it is enabled. setitem ('islogin', 1); window. onbeforeunload = function () {// if it is disabled, the record is deleted. Otherwise, localstorage is unavailable. removeitem ('islogin');} window. addeventlistener ("Storage", function (e) {If (E. key = 'new') {console. log (E. newvalue) ;}}, false );
Cross-page listening in the same domain