<!doctype html> <html lang="en"> <head> <title>JavaScript Editor</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta charset="utf-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> </head> <body> <div id="page"></div> <div id="editor" contenteditable="true" style="border: 1px solid black;padding: 0px;"></div> <script> $("#editor")[0].innerText=localStorage.html // editor <- var $("#page").html(localStorage.html) // page <- var function sync(){ localStorage.html=$('#editor')[0].innerText; // var <- editor $("#page").html(localStorage.html) // page <- var } </script> <button onclick="sync()">sync</button> <input type="checkbox" id="auto_sync"> <script> setInterval(function(){ if($("#auto_sync").is(':checked')) sync() },1500) </script> </body> </html>