472,127 Members | 2,130 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

How can I check when an IFRAME is loaded ?

Eli
Hi,

I've created a dynamic IFRAME and inserted it in the document. Then I
changed the src property to some URL (not the same domain as the main
document). I want to check when the IFRAME is loaded and then get its
title to put in the main document.

function GetTitle()
{
var
ifr_title=document.getElementById('myiframe').cont entWindow.document.title;
alert('The IFRAME was loaded and its title is:\n'+ifr_title);
}
var ifr=document.createElement('IFRAME');
ifr.id='myiframe';
ifr.style.width='100%';
ifr.style.height='100%';
ifr.src='http://www.php.net';
ifr.onload=GetTitle;
document.appendChild(ifr);

But it seems that the GetTitle() function is never called, tho the
IFRAME was loaded. How can I make this work?

-thanks, Eli

Jul 23 '05 #1
1 2437


Eli wrote:
I've created a dynamic IFRAME and inserted it in the document. Then I
changed the src property to some URL (not the same domain as the main
document). I want to check when the IFRAME is loaded and then get its
title to put in the main document.

function GetTitle()
{
var
ifr_title=document.getElementById('myiframe').cont entWindow.document.title;
alert('The IFRAME was loaded and its title is:\n'+ifr_title);
}
var ifr=document.createElement('IFRAME');
ifr.id='myiframe';
ifr.style.width='100%';
ifr.style.height='100%';
ifr.src='http://www.php.net';
ifr.onload=GetTitle;
Try
if (ifr.addEventListener) {
ifr.addEventListener('load', GetTitle, false);
}
else if (ifr.attachEvent) {
ifr.attachEvent('onload', GetTitle);
}
document.appendChild(ifr);
You need to append the ifr to
document.body.appendChild(ifr);
But it seems that the GetTitle() function is never called, tho the
IFRAME was loaded.


Your script in the main document is not allowed to read out the title of
the document in the iframe if that document is loaded from a different
origin.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Halldór Ísak Gylfason | last post: by
3 posts views Thread by Catherine Lynn Smith | last post: by
2 posts views Thread by Christian Schmitt | last post: by
4 posts views Thread by christine.nguyen | last post: by
3 posts views Thread by Stevie_mac | last post: by
1 post views Thread by knkk | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.