There are several topics on this, but none that completely answer my question.
I would like to be able to have a link which loads a whole HTML file into a DIV.
This, for example, will load just text into my "MainBack" DIV. It works fine:
<a href="#computing" onclick="document.getElementById('MainBack').innerHTML = '<p>1</p>';">Computing</a>
but I would like to load an entire file into it like this:
<a href="#computing" onclick="document.getElementById('MainBack').innerHTML = 'HTML FILE';">Computing</a>
Any advice? I'm pretty new to this!
You can use an <iframe>
to do just that:
<iframe src="link.html" width="100%" height="300"></iframe>
Live Demo
Code:
<a href="#computing" onclick="document.getElementById('MainBack').innerHTML = '<iframe src=\'http://www.google.com\' scrolling=\'no\' frameborder=\'0\' width=\'100%\' height=\'600px\'></iframe>'">Computing</a>
Or you could use lightbox to do it in a really pretty manner...
It will display; photos, videos, HTML... basically anything you want.
Using the jQuery ajax API you can grab the content of a particular tag inside the document from some URL:
<a href="#computing"
onclick="$('#MainBack').load('/path/file.html body')"
>
Computing
</a>
Important:
#MainBack
is the ID of the placeholder tag in your parent document/path/file.html
id the URL for the document you want to load data frombody
is the tag holding the content you want to load.What can go wrong:
iframe
solution from the other answer.<a href="#computing" onclick="document.getElementById('MainBack').innerHTML = '<iframe src=\'http://www.google.com\'></iframe>'">Computing</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With