I have two HTML pages.
Index.html
<div id="source">
Contenido de Usuario
</div>
<input type="button" id="export" value="Export Data">
Users.html
<div id="target">
</div>
How to display the content of the source <div>
element in Index.html inside the target <div>
element in Users.html with JavaScript?
2
Answers
Use the
fetch()
API.Index.html
Users.html
You may need to sanitize the HTML content first as well, just to make sure it’s safe to append using, for example, DOMPurify.
You make no mention of the size of this source or what kind of data it is… both of which are very important in making an informed decision.
Anyway, assuming the size is less than 2.5MB and the data is plain text with nothing special in there, I guess you can…
In Index.html
In Users.html
NB: Untested pseudo-code suggestion.
Update: So an hour later you decide to introduce a button into the equation eh… not very smart!