@TheBearMayMay 09.2008 — #Here's one I wrote a while back that works in IE and FF:
[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>JS Include</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> function getFile(fileName){ oxmlhttp = null; try{ oxmlhttp = new XMLHttpRequest(); oxmlhttp.overrideMimeType("text/xml"); } catch(e){ try{ oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){ return null; } } if(!oxmlhttp) return null; try{ oxmlhttp.open("GET",fileName,false); oxmlhttp.send(null); } catch(e){ return null; } return oxmlhttp.responseText; }
var incArr; window.onload = processInclude;
function processInclude() { incArr = document.getElementsByTagName("inc"); dNode=document.createElement("div"); dNode.innerHTML=getFile(incArr[0].attributes.file.nodeValue); tNode=incArr[0]; tNode.parentNode.replaceChild(dNode, tNode); //Array is now invalid so a regular loop won't work if(document.getElementsByTagName("inc").length > 0) processInclude(); } </script> </head>
@Sirin86May 09.2008 — #So you're trying to drop HTML from another page into a div without using JS? With AJAX you'd probably have to use something server-side, unless you request the object directly.
You could use an iframe, but the best way to do it I think is through AJAX. And the best way to do AJAX is with a library, a good one is [url=http://www.prototypejs.org/]Prototype[/url]. Then, you can go: <i> </i><div id = "myDiv"></div> <input type = "button" onclick = "fillDiv()" value = "Fill Div" /> <script> function fillDiv(){ new Ajax.Updater("myDiv", "path/to/file.html"); } </script>
This requests the file at the URL you specify and dumps the content into the element you specify (in the example, myDiv).