新建两个aaa.html 、bbb.html 文件
aaa.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>处理中...</title> </head> <body> <script type="text/javascript"> let htmlJson = { transAssembledUrl: "html完整源代码", // 所有html代码 } localStorage.removeItem('callbackHTML'); localStorage.setItem('callbackHTML',htmlJson.transAssembledUrl); window.location.href = window.location.href.split('/aaa')[0] + '/bbb.html'; </script> </body> </html>
bbb.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>html源代码页面</title> </head> <body> <script type="text/javascript"> let htmlJson = localStorage.getItem('callbackHTML') console.log(htmlUnescape(htmlJson)) // 返回的完整html源代码可能会已经转义,现在再转回去,如接受的是为转义的,可注释 function htmlUnescape(html) { return html.replace(/<|>|"|&/g, match => { switch(match) { case '<': return '<'; case '>': return '>'; case '"': return '"'; case '&': return '&'; } }) } document.write(htmlUnescape(htmlJson)); document.close(); </script> </body> </html>