tags:

views:

216

answers:

4

Is it possible to show a html file in a div element??

+3  A: 

If you want to show the source code make an ajax request to that file and put the response inside the div. If you want to show a working html page use an iframe and put it inside the div.

mck89
+1  A: 

Do you mean show the HTML markup? In which case you can wrap the code in the "<pre>" tags to display it. If you mean to embed some HTML inside a div tag, you can set the div's innerHTML property to a string containing the HTML.

Tom Woolfrey
+2  A: 

Don't know your environment, but I can suggest you to take a look at JQuery and its method to load an external HTML into a DOM object.

m.bagattini
A: 

Certainly! Just be sure you've properly escaped the contents of the file (so < becomes &lt;, &amp; becomes &amp;amp; et cetera). This is easy to do in any web-oriented programming language (like PHP or ASP), and not overly difficult to do in other languages. Doing it by hand would be fairly tedious, but you can find tools online to do it for you.

The result would be something like:

<div>
    &lt;!DOCTYPE ... &gt;
    &lt;html&gt;
    ...
    &lt;a href="something?foo=bar&amp;amp;morefoo=morebar"&gt;...
</div>

To the viewer, this will render as normal HTML inside your <div>.

VoteyDisciple
David Dorward
VoteyDisciple