View RSS Feed

molendijk

Extract external HTML via a hidden text/html-object

Rate this Entry
In the head:
Code:
<!--[if IE]>
<script type="text/javascript">
document.write('<object type="text/html" id="object_id" width="0" height="0" data="menu.html"><\/object>');
onload=function(){
document.getElementById('main_page_id').innerHTML = document.getElementById('object_id').object.documentElement.innerHTML;
}
</script>
<![endif]-->
<!--[if !IE]><!-->

<script type="text/javascript">
/*We could do a document.write for the object, but we do it the dom-way */
var OBJ = document.createElement("object");
OBJ.setAttribute("type", "text/html");
OBJ.setAttribute("data", "menu.html");
OBJ.setAttribute("id", "object_id");
OBJ.setAttribute("width", "0px");
OBJ.setAttribute("height", "0px");
document.documentElement.appendChild(OBJ);

onload=function(){
transfer = document.getElementById('main_page_id');
while(transfer.hasChildNodes())transfer.removeChild(transfer.firstChild);
transfer.appendChild(document.getElementById( 'object_id').contentDocument.documentElement.cloneNode(true));
}
</script><!--<![endif]-->
In the body:
Code:
<div id="main_page_id"></div>
See HERE for demos and detailed explanations.
===
Arie Molendijk.

Submit "Extract external HTML via a hidden text/html-object" to del.icio.us Submit "Extract external HTML via a hidden text/html-object" to StumbleUpon Submit "Extract external HTML via a hidden text/html-object" to Google Submit "Extract external HTML via a hidden text/html-object" to Digg

Updated 05-05-2009 at 11:49 PM by molendijk (Correction)

Tags: None Add / Edit Tags
Categories
Post a JavaScript

Comments

  1. molendijk's Avatar
    Corrected an error in the script (given above).
    Made sure that the demos validate.
    ===
    Arie