How to make edits on webpage that change display on another webpage

為{幸葍}努か 提交于 2020-04-30 07:12:07

问题


I am not using a database or sql. This is the HTML and Javascript for my current design. I want the ability to change the hours offset on another customization page and for those changes to apply to the display page that the clocks are on. I currently change the offsets from the display page by typing in the TimeZone database name or by typing in the correct timezone offset. So in simple terms I am trying to change the timezone input from another webpage and have it still displayed from my display webpage. Thanks!

const OptionsMilitary = { hour12:false, hour:'2-digit', minute:'2-digit', second:'2-digit' };

const MilitaryTime=(elm, dt)=>
  {
  let [hh,mm,ss] = dt.toLocaleString("en-US", {...OptionsMilitary, timeZone:elm.dataset.timeZone }).split(':')
  if ('seconds'in elm.dataset) elm.dataset.seconds = ':'+ss
  elm.textContent = (hh=='00'&&mm=='00') ? '2400' : (hh+mm).replace(/^24/, '00'); // specific browsers marmelade
  }

setInterval(() => {
  let dateTime = new Date();
  document.querySelectorAll('.timZonM').forEach(el=>MilitaryTime(el, dateTime));
}, 500);
div.timZonM { /* military time */
  width: 3em;
  margin:.3em;
  color: navy;
  font-size: 20px;
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: .05em;
}
div.timZonM::after {
  content: attr(data-seconds);
  color:crimson;
}
<div class="timZonM" data-time-zone="Asia/Tehran" style="position: absolute; left: 10px; top:545px;"></div>
<div class="timZonM" data-time-zone="Etc/GMT" style="position: absolute; left: 250px; top: 545px;"></div>
<div class="timZonM" data-time-zone="Etc/GMT+4" data-seconds style="position: absolute; left:510px; top:580px;"></div>
<div class="timZonM" data-time-zone="Etc/GMT-8"  style="position:absolute; left:920px; top:545px;"></div>
<div class="timZonM" data-time-zone="Etc/GMT-14" style="position:absolute; left:1205px; top:545px;"></div>

来源:https://stackoverflow.com/questions/60935454/how-to-make-edits-on-webpage-that-change-display-on-another-webpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!