Saturday, 15 July 2023

html previewer Tool

In this example, the HTML code is entered in the <textarea> element with the class code-editor. The real-time preview is displayed in the <iframe> element with the id previewFrame.

The JavaScript code listens for any changes in the code editor and updates the preview iframe accordingly by writing the HTML code into its document.

Feel free to customize the styling, add more features, and enhance the functionality as per your requirements.


<!DOCTYPE html>
<html>
<head>
  <title>HTML Previewer Tool</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f7f7f7;
      margin: 0;
      padding: 0;
    }

    .container {
      max-width: 800px;
      margin: 20px auto;
      padding: 20px;
      background-color: #fff;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }

    h1 {
      color: #333;
      text-align: center;
    }

    .code-editor {
      width: 100%;
      height: 300px;
      margin-bottom: 20px;
      border: 1px solid #ccc;
      border-radius: 3px;
      padding: 10px;
    }

    .preview {
      background-color: #f9f9f9;
      padding: 10px;
      border-radius: 3px;
    }

    .preview iframe {
      width: 100%;
      height: 100%;
      border: none;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>HTML Previewer Tool</h1>

    <textarea id="codeEditor" class="code-editor" placeholder="Enter your HTML code here"></textarea>

    <div class="preview">
      <iframe id="previewFrame"></iframe>
    </div>
  </div>

  <script>
    const codeEditor = document.getElementById('codeEditor');
    const previewFrame = document.getElementById('previewFrame');

    codeEditor.addEventListener('input', updatePreview);

    function updatePreview() {
      const code = codeEditor.value;
      const previewDoc = previewFrame.contentWindow.document;
      previewDoc.open();
      previewDoc.write(code);
      previewDoc.close();
    }
  </script>
</body>
</html>

No comments:

Post a Comment

configuration of website

Menu Type: Dropdown with Full Width Ensure the navigation items in the dropdown menu contain relevant keywords related to the we...