...

View Full Version : iFrame reference



gnomeontherun
05-06-2008, 11:06 PM
I'm trying to call a javascript function inside of an iframe, from the parent window. I even am using this function which may or may not be working.



var getiframe= getIFrameDocument("stupidiframe");
getiframe.alertTest();

function getIFrameDocument(framename) {
var videoFrame =
document.getElementById(framename);
var doc = videoFrame.contentDocument;
if (doc == undefined) // Internet Explorer
doc = videoFrame.contentWindow.document;

return doc;
}

Of course I have an iframe in the body like this.


<iframe id="stupidiframe" name="stupidiframe" allowtransparency="true" src="example.html" width="400" height="300" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>


And inside the iframe the page has a function like


alertTest {
alert("Testing...");
}

How can I get this to work? I'm pretty sure its how I try to call the function inside of the iframe.

mjlorbet
05-07-2008, 02:26 AM
if the function is global within the scope of the iframe, you need to reference it in the window scope



yourIframe.contentWindow["yourFunction"]();

gnomeontherun
06-09-2008, 05:49 AM
Ok I'm still not getting this to work, and I don't know if there is any connection to the contents of the page having Flash. I rearranged the code and have a different situation with a similar problem. I found some code from Aero, which opens the iframe just fine. Now I want to close it



<script language="javascript" type="text/javascript">

function showIFrame()
{
if (!document.getElementById("videoframe")) {
var iframe = document.createElement("iframe");
iframe.setAttribute("id","videoframe");
iframe.setAttribute("name","videoframe");
iframe.setAttribute("height","370");
iframe.setAttribute("width","490");
iframe.setAttribute("frameBorder","1");
iframe.setAttribute("scrolling","no");
iframe.setAttribute("src","example.html");
iframe.style.position = "absolute";
iframe.style.display = "block";
iframe.style.bottom = 0 + 'px';
iframe.style.left = 0 + 'px';
window.document.body.appendChild(iframe);
return false;
}
else {
document.getElementById("videoframe").style.visibility = "visible";
document.getElementById("videoframe").style.display = "block";
}
}

function openWindow(){
showIFrame();
}

// Closes window
function closeWindow() {
document.getElementById("walkonvideoframe").style.visibility = "hidden";
document.getElementById("walkonvideoframe").style.display = "none";
document.getElementById("walkonvideoframe").width = 0;
document.getElementById("walkonvideoframe").height = 0;
var iframe = document.getElementById('walkonvideoframe');
iframe.parentNode.removeChild(iframe);
}

</script>

<br /><a href="#" onclick="openWindow();">Play Video</a>
<br /><a href="#" onclick="closeWindow();">Close Video</a>


And in FF it closes the Iframe and kills the Flash application, but in IE I can still hear the audio. Is there a way to take the iframe from the DOM?

Secondly, then I want to have the contents in the Iframe call the parent document to close the Iframe on video completion. I have the on completion part working, but it doesn't seem to call the parent frame at all.

Code for the page inside the IFrame


function closeFlashWindow() {
parent.document.getElementById("videoframe").style.display="none";
parent.document.getElementById("videoframe").style.visilibity="hidden";
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum