How can I save HTML locally with JavaScript?

JavascriptWeb DevelopmentFront End Technology

To save HTML locally with JavaScript, create an HTML file and save the following code in it. The code is for cookies in JavaScript −

<!DOCTYPE html>
<html>
   <body>
      <p id="visits"></p>
      <script>
         var visits = parseInt(document.cookie.split("=")[1]);
         if (isNaN(visits)) visits = 0;
         visits++;
         document.cookie = "visits =" + visits;
         document.getElementById("visits").innerHTML = "The page ran " + timesVisited + " times.";
      </script>
   </body>
</html>

Just save the above file and open in a web browser.

raja
Updated on 15-Jun-2020 13:14:54

Advertisements