1

My index.html file looks like this.

<body>
  <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#f2f2f2" align="center" id="edmTable">

    <!-- Content goes in here -->

  </table>
  <script src="main.js"></script>
</body>

</html>

The main.js file renders a bunch of HTML within the table tags. If I view the page source of the rendered HTML you get the above code instead of the rendered HTML.

I have to open the element inspector > right-click > edit as HTML to get the HTML markup.

My goal: I would like to output the rendered HTML into a separate HTML file.

I've tried to Google this and I don't know how to word it to get the information I need.

Is there a node or gulp plugin that could help me achieve this that you could point me in the direction of?

Ideally the HTML file would be outputted on save or page load. This is because the main.js renders the content based on a JSON file. So I can easily update the JSON and load the page and I can see the rendered markup.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Moe-Joe
  • 1,012
  • 3
  • 15
  • 27
  • Define "into an separated file". Are you trying to make the used download the html from a click? As if it was a file? Are you trying to write the file to the user's computer? – Ismael Miguel Dec 13 '16 at 22:11
  • I would like to simple output a HTML on save. It's for local use. – Moe-Joe Dec 13 '16 at 22:14
  • 1
    I imagine this is as simple as getting the element using `document.getElementById` and getting its `outerHtml` property. Then again, maybe not. –  Dec 13 '16 at 22:20
  • "simple output a HTML on save." <-- 1- **Nothing** is simple (in web-dev). 2- you are skipping the question. What do you want? A save dialog to show? Write the file to disc? – Ismael Miguel Dec 13 '16 at 22:21
  • I think you should use dom.ready(). so when javascript add json content to dom, save it then. – flakerimi Dec 13 '16 at 22:23
  • @Amy I imagine it as grabbing the HTML and using an `Text`, where the `href` will have a base64 representation of the HTML. – Ismael Miguel Dec 13 '16 at 22:23
  • @IsmaelMiguel I'll try and explain it more. I open index.html or a node plugin is run and a HTML file of the rendered HTML is outputted. It writes the HTML file to my local disk – Moe-Joe Dec 13 '16 at 22:31
  • Possible duplicate of [get a browser rendered html+javascript](http://stackoverflow.com/questions/18720218/get-a-browser-rendered-htmljavascript) – Heretic Monkey Dec 13 '16 at 22:38
  • To get the rendered HTML, use inner/outerHTML – Ruan Mendes Dec 13 '16 at 22:39
  • @Moe-Joe If you have node.js, you can do that easily. Otherwise, just hack your way through, like we all do. And that is unreliable. – Ismael Miguel Dec 13 '16 at 22:40
  • @amy and juan. Thanks. outerHTML works fairly well. Maybe Ill start looking into node to output the rendered HTML. – Moe-Joe Dec 13 '16 at 23:05

0 Answers0