473,468 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Iframe check

107 New Member
Hey,

Ive got a compatability problem....

Im trying to check when an Iframe is done loading...

Can someone tell me why this doesnt work in Firefox but it does in IE:


--------------------------------------------------------------------
[HTML]<html>
<head>
<title>Check Statistics</title>

<script type="text/javascript" language="JavaScript"><!--
function StateChanged(){
var iframe = document.getElementById("stats");
alert("ready state change to: " + iframe.readyState);

if (iframe.readyState == "complete")
{
Done();
}
}

function start(){
var iframe = document.getElementById("stats");
iframe .setAttribute("src","http://google.com");
iframe .onreadystatechange = StateChanged;
}

function Done(){
alert("Done");
}

//-->
</script>

<body onload="start();">

<a href="#" onclick="GetStats();">Get Statistics</a>

<div>
<iframe id="stats" width=720 height=500 src="" frameborder="yes"
scrolling="no"></iframe>
</div>
</body>
</html>
[/HTML]-----------------------------------------------
(didnt use code tags because then it pastes with the line numbers =(

Cheers!


Andy
Sep 12 '08 #1
9 11783
theS70RM
107 New Member
ok, so as soon as i set iframe.src = "whatever.html"; then iframe.document should exist..... well it does in IE, but not in Firefox.

Anybody know a way round this??
Sep 12 '08 #2
acoder
16,027 Recognized Expert Moderator MVP
(didnt use code tags because then it pastes with the line numbers =(
Doesn't make them voluntary. You can click on reply to copy/paste without line numbers.

Onto your question: use onload.
Sep 12 '08 #3
theS70RM
107 New Member
hmm, do you mean use the onload property of the document that is to be loaded?

I thought about that, I could edit the actual document to be loaded in the iframe and get it to call a function in the parent once it's loaded... I dont want to do that because it means editing every document I ever load in there, some I will not be able to as they are external.

If you're talking about something like this:


Expand|Select|Wrap|Line Numbers
  1. myiframe = document.createElement("iframe");
  2. myiframe.src = "myurl/mypage.php";
  3. myiframe.document.body.onload = function(){ alert("ive loaded!"); }
  4.  

then it still does me no good, I cant access the document property in this way until the page has actually loaded.. that's the whole problem.

Any other ideas???


Cheers


Andy

ps. note the expert use of code tags =P
Sep 15 '08 #4
theS70RM
107 New Member
it doesnt seem right to me, can someone test the above code in firefox please :-\
Sep 15 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
I meant something like myiframe.onload. See if that works.
Sep 15 '08 #6
theS70RM
107 New Member
hmmm, well that does get called when the iframe has been loaded. But i think that's seperate from the contained document's onload function.

My ultimate aim is simply to get the height of the contained document so I can ammend the iframes height to suit.
Sep 15 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
Use the contentDocument to get the document contained within the iframe.
Sep 15 '08 #8
theS70RM
107 New Member
aha, that's what I've been missing.


I've never used that property before but it seems to do the trick nicely.


Thanks very much!


Andy
Sep 16 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
Glad it worked :)
Sep 16 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rich | last post by:
Is there any way I can check to see if a document is loaded into the iframe before I call onLoad (sort of an afterLoad). I'm loading up a page into an iframe. But because we use four servers...
3
by: Lans Redmond | last post by:
I have an iframe within a jsp page which displays rows from a database. I then have a checkbox where, when I check/uncheck the checkbox it performs operations on the rows listed in the frame. I...
1
by: Eli | last post by:
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...
16
by: Mcginkel | last post by:
I am trying to find a way to load XHTML content in an Iframe. I use to do this in html by using the following code : var iframeObject = document.createElement("iframe");...
1
by: Jason | last post by:
Hi I have client side script that inserts an IFrame into a table cell upon a particular client side click event. My problem is that when a postback occurs, that IFrame "disappears". what do i do...
7
by: Asterbing | last post by:
Hi, Talking about a js script which changes an iframe src through a "ref_to iframe.setAttribute("src", document_path);", I would like to launch a check() fct when this new document is loaded. ...
3
by: Asterbing | last post by:
Since the "on fly addition..." thread has taken another direction, I'm opening a new one to be more explicit and recenter the subject. Well, the subject is to detect when a document is well...
1
by: Laphan | last post by:
Hi I'm dynamically building up an iFrame (in other words it doesn't have another web page as it's source) and I need some way of checking via JS if the iframe contains any HTML/text before the...
3
by: laredotornado | last post by:
Hi, Does anyone know a cross-browser way of making an iframe just as big as the HTML content of its source, but no bigger, either width or height wise. Using 100% attributes for iframe width...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.