简体   繁体   English

打开html代码作为文件预览

[英]Opening html code as a file preview

I am fetching the HTML code from some external API. 我正在从某些外部API获取HTML代码。 On my website, I want to create an anchor, which will open a new tab showing that HTML code parsed. 在我的网站上,我想创建一个锚点,该锚点将打开一个新选项卡,其中显示了已解析的HTML代码。 How can I do that? 我怎样才能做到这一点?

One way I know of is to just make an iframe, and show the code there, but that won't open a new tab and won't adjust the size easily. 我知道的一种方法是只制作一个iframe,然后在其中显示代码,但这不会打开新标签,也不会轻易调整大小。

What's the best way to solve this? 解决此问题的最佳方法是什么? I am using node.js express as a website's server. 我正在使用node.js express作为网站的服务器。

you could use window.open(" your url here ") javascript function. 您可以使用window.open(“ your url here ”)javascript函数。 You could just use an onclick attribute to call it like below: 您可以只使用onclick属性来调用它,如下所示:

<span onclick='window.open(" your url here ")'>view</span> <span onclick='window.open("您的网址在这里")'>view</span>

after which you could replace contents of a tag (lets say the body tag) with the html code received from the external API with standard javascript 之后,您可以使用标准javascript用从外部API接收到的html代码替换标签的内容(比如body标签)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM