Skip to content
Advertisement

How to copy HTML content into a new tab [closed]

I am building a web app and I need to copy an HTML div and everything inside it into a new tab. I am writing this code in JavaScript. So far I have been working on creating a blob and then creating a file to download. This approach copies all the HTML code I need BUT it does not copy the text that has been inputted into any text fields. As I understand, the problem is that the entered text is not part of the HTML code so it cannot be copied. However I cannot find another approach to this, please assist. Thank you

Advertisement

Answer

(Inspired by comment by @vanowm)

First, copy the html (say inside a DIV)

Then you’ll need loop through all input fields and read their value so you can apply them.

So the code is like this (amend to suit your further needs):

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement