简体   繁体   中英

Opening html code as a file preview

I am fetching the HTML code from some external API. On my website, I want to create an anchor, which will open a new tab showing that HTML code parsed. 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.

What's the best way to solve this? I am using node.js express as a website's server.

you could use window.open(" your url here ") javascript function. You could just use an onclick attribute to call it like below:

<span onclick='window.open(" your url here ")'>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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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