How to load a page in a div?

I was told that using Divs instead of iframes is the way forward, so I use frames from my banner and main body. How to load my index.html into my div?

+8
javascript html
source share
6 answers

tried .load () jquery. With server-side technology, you can do it easily.

+6
source share

Using jQuery:

jQuery('#myDiv').load('http://example.com/somefile.html'); 

Without jQuery:

 var request = new XMLHttpRequest(); request.open('GET', 'http://example.com/somefile.html', true); request.onreadystatechange = function (anEvent) { if (request.readyState == 4) { if(request.status == 200) { document.getElementById("myDiv").innerHTML = request.responseText; } } }; request.send(null); 

I usually use this approach to dynamically load small pieces of content. It is probably a bad idea to use a div if you are loading an extremely large amount of content (like an entire page). An IFrame would be better for this scenario.

+5
source share
 $(".divClassHere").load("url path here"); 

However, it sounds more likely to me like you after the MasterPage structure (if you have ASP.NET) or importing files

+2
source share

Some people say that objects instead of iframes are the way forward. But divs and iframes are completely different things. Iframe is like a separate page on a page. This has a different context, different scripts, different css ... A similar result can be achieved using the object. But nothing like this can be done with a div.

You can upload content in a div. You can use javascript to change the contents of a div. With an ajax call, you can get the contents of a url that can be placed in a div using javascript.

But this is completely different from iframes.

+2
source share

You create a separate page for each individual document that you have, then you use some form of the template or include system to automatically duplicate the common content.

+1
source share

What server language are you using?

try using your server language first to achieve this. For example, if you use PHP, you can use include

and if you use ColdFusion use cfinclude

and if you said to do it through javascript, then the only way is Ajax.

0
source share

All Articles