我正在与一些看似简单的东西作斗争。我有一个包含DOM元素的javascript字符串,想要打开一个新窗口(window.open()?)并使用字符串填充新窗口。即让浏览器获取字符串并将其即时转换为HTML。这个是可能的吗?
发布于 2013-07-06 00:10:46
是的,这是可能的……
var wnd = window.open("about:blank", "", "_blank");
wnd.document.write(html);
这应该能起到作用。
发布于 2016-06-27 14:16:32
阿切尔的回答是最好的方法。但您需要关闭文档才能在"htmlString“中运行脚本。
var wnd = window.open("about:blank", "");
wnd.document.write(htmlString);
wnd.document.close();
发布于 2019-11-15 00:03:40
如果你需要新的标签,你可以使用这个。
const win = window.open('about:blank', '_blank');
win.document.write('<h1>test</h1>');
win.focus();
https://stackoverflow.com/questions/17493027
复制相似问题