Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I load a page in a div?

I've been told that using Divs instead of iframes is the way forward, so I'm using frames from my banner and main body. How do I load my index.html into my div?

like image 894
code511788465541441 Avatar asked May 24 '11 15:05

code511788465541441


3 Answers

did u try .load() of jquery. with server side technology you can do this easily.

like image 81
MLS Avatar answered Oct 31 '22 14:10

MLS


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);

Typically I use this approach to load small snippets of content dynamically. It's probably a bad idea to use a div if you're loading an extremely large amount of content (like an entire page). An iframe would be better for that scenario.

like image 29
Vivin Paliath Avatar answered Oct 31 '22 15:10

Vivin Paliath


$(".divClassHere").load("url path here");

However, it sounds to me more like you're after a MasterPage structure (if you've got ASP.NET) or file imports

like image 2
Curtis Avatar answered Oct 31 '22 15:10

Curtis