Tengo un código de plantilla HTML como
<!doctype html> <html> <head> <title>Our Funky HTML Page</title> <meta name="description" content="Our first page"> <meta name="keywords" content="html tutorial template"> </head> <body> Content goes here. </body> </html>Quiero generar un enlace en mi plantilla html que represente este código en una nueva página Por ahora he hecho una función como esta
function stringToHtml(htmlString: string) { let parser = new DOMParser(); let doc = parser.parseFromString(htmlString, 'text/html'); return doc.body; }que toman la cadena html (mi plantilla) como argumento.
En mi plantilla (donde necesito representar este enlace) interpolo esta función
function generateLink(myHtmlTemplate: string, text: string){ const page = stringToHtml(myHtmlTemplate) return `<a href="${page}" target="_blank">${text}</a>` }Pero no sé qué puedo hacer para abrir el renderizado HTML después de hacer clic en el enlace