...

View Full Version : Iframe specific content



attasz
05-04-2010, 05:38 PM
Is it possible to take a specific content into iframe?
I mean i have an iframe on page 1.
I want to take into this iframe a div (let's say id="myDiv") from page 2,but only "myDiv" should appear in the iframe.

Fang
05-05-2010, 09:25 AM
If both documents are in the same domain:
function copyIt() {
var iframe = document.getElementsByTagName("iframe")[0]; // first iframe
var p = document.getElementById("myDiv");
var p_copy = p.cloneNode(true);
iframe.contentDocument.body.innerHTML = '';
iframe.contentDocument.body.appendChild(p_copy);
}

attasz
05-05-2010, 10:37 AM
Sorry,i forgot to say the two pages are on different domain.

Fang
05-05-2010, 12:09 PM
Load your own blank document into the iframe then use the script

attasz
05-05-2010, 01:35 PM
Sorry,i don't get it.I understand your function,but how can i pass the page where my div derives from,to javascript?

Fang
05-05-2010, 02:58 PM
function copyIt() {
var iframe = document.getElementsByTagName("iframe")[0]; // first iframe
iframe.src='blank.html'; // load empty document
var p = document.getElementById("myDiv"); // the element you want to copy
var p_copy = p.cloneNode(true); // copy the element
iframe.contentDocument.body.innerHTML = ''; // clear the iframe document
iframe.contentDocument.body.appendChild(p_copy); // add the element to the iframe document
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum