Mar 31, 2013

Embed part of a website

If you do know the id of the div the table is in you can do something like this:

Method #1:

HTML:

<div id="PlaceToPutTable"></div>
<iframe id="iframe" src="urlofpagewithtableonit.html" style="display:hidden;"></iframe>

Javascript:

var iframe = document.getElementById("iframe");
var div = document.getElementById("PlaceToPutTable");
div.innerHTML = iframe.contentWindow.document.getElementById("KnowDivName").innerHTML;


 


Method #2:


You can put the part of an external website starting at some id into an iframe, like this. Or you can put an iframe into a div like this.

This is a div with id="promo2" of the BCC site:
<iframe src="http://www.bbc.co.uk/#promo2" scrolling="no" frameborder="no" width="634" height="300"></iframe>


 


Method #3:


As an addition to @jini's answer, you could make that script into a file, gateway.php, and load things using only jQuery:

$('#container').load('gateway.php?url=foo.com #target_div');


And a possible gateway.php:

<?php    
print file_get_contents($_GET['url']);
?>


 


SOURCE, SOURCE 2

No comments: