Question

I created an API of sorts, that when you navigate to it, returns information in html.

On my website, I would like to have the web page reach out to the API and display the information as part of the web page (sort of like a webpage reaches out for an img). What HTML tag would be best suited to achieving this result? I came across the and tags but not really sure which would be best.

I am building this myself thus have full control over how the content is delivered back to the page. Is there specific pattern that is used for such "modular" sourcing of information? I could rewrite my website to - prior to serving the web page - reach out to the api and pull the info itself and then include the results in html but a) this would be more complex and require changes in several places b) will become really complex as the number of such api call results I would want to include increases.

Was it helpful?

Solution

You can use Iframe for this purpose and when you recieve html which you want to display , you can simply set html content in that iframe's ID :

document.getElementById('myIframe').contentWindow.document.write("<html><body>Here is your html</body></html>");

Hope this helps.

OTHER TIPS

As far as i know, using iframes is rather depricated. I always use div-tags for such tasks.
document.getElementById("targetdiv").innerHTML = "New HTML-Content"; More info on divs: http://www.w3schools.com/tags/tag_div.asp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top