View Full Version : Loading exnternal pages into div
I've been searching the net for a few hours now for a js that i can use <a href="http://www.sitename.com/#content/home">Home</a> load into a div, but i cant seem to find one, anyone got any ideas? or good links to any.
08-27-2010, 07:32 PM
Not a good idea.
A full HTML page will have <html> and <head> and <script> and <style> and <body> tags that will not work if plopped into a <div>.
You *might* get away with the <script> and <style> tags (but you might not! if they conflict with styles and script already in your page!) but the <html>, <head>, and <body> tags (and probably others) would be illegal and pure poison in the <div>.
You *might* be able to strip out everything from the page except the text *between* (but no including) the <body> and </body> tags, but it could also be pure luck if it works.
Finally, you can *NOT* do this if the page you are attempting to load is in another domain. That's not allowed. Period.
No it not if you dont put them in the external page.
08-28-2010, 12:35 AM
Well, sure... If *YOU* have control over all the external pages, then it's TRIVIAL!
var http = (window.XMLHttpRequest != null )
? new window.XMLHttpRequest()
: new ActiveXObject("Microsoft.XMLHTTP");
http.open( "GET", "urlOfSomeOtherPage.html", false );
http.send( null );
document.getElementById("SomeDiv").innerHTML = http.responseText;
(That's doing the load synchronously. You could also do it async, with only a tiny bit more work.)
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.