let share = (function() { const elCombo = document.getElementById("mycombo"); const elBtn = document.getElementById("btn-openwin"); return { elCombo: elCombo, elBtn: elBtn } })(); window.addEventListener("load", () => { share.elCombo.addEventListener("change", e => window.localStorage.setItem("fruit", e.target.value)); share.elBtn.addEventListener("click", e => { let wWidth = 880, wHeight = 300; let x = (window.innerWidth - wWidth) / 2; let y = (window.innerHeight - wHeight) / 2; let winSpec = `width=${wWidth},height=${wHeight},left=${x}, top=${y},menubar=no,status=no`; window.open("./sub.html", "", winSpec); }); }); window.addEventListener("storage", e => { const elApplyOption = share.elCombo.querySelector(`option[value="${e.newValue}"]`); let index = Array.from(share.elCombo.children).indexOf(elApplyOption); share.elCombo.selectedIndex = index; });