PDA

View Full Version : Need an alternative to an IFRAME onLoad event to support IE5.00 clients


MattyUK
11-27-2002, 04:29 PM
At teh moment I have an IE5.5 only script that uses an onload event from the IFRAME tag to fire off a function. Only IE5.5+ seems to support this event to an IFRAME tag according to Mickysoft documentation.

I need to fire the function ONLY when the IFRAME has loaded and not before (so timers are out). Ideally I'd need to fire the function ONLY when the IFRAME had loaded a document containing a specific number of semi colons ";". However I now need to make this all IE5.00 and IE5.01 compatible.

What alerternatives are there to the IFRAME onLoad event as I've been using it?
Would it be best to write a function that checks and keeps checking if the IFRAME has loaded before proceeding?
How can I do that without sending the browser into a loop or resouce chewup assuming the IFRAME fails to load the target file?

What is the best way to proceed for this goal?

An Overview:
The function fired by the IFRAME onLoad reads the contents of the IFRAME target file and builds a data array around them. However the file may not always be loaded, in which case it needs to fail without error. I need the script and HTML to be good for IE5.00 at least.

I'd appreciate any help.

MattyUK

brothercake
11-27-2002, 04:57 PM
I had the same problem a while ago .... but I never found a solution. I was hoping the "readyState" property would do it .... but it was similarly impotent in 5.0

The best way I can suggest would be have a <body onload in the page inside your iframe, and use that.

MattyUK
11-27-2002, 05:15 PM
Great idea. Unfortunately it is an unformatted (irregular formatted) text file rather than a structured markup (html) file. I can't push and code, events or markup into it.

I could read something of the loaded files properties to confirm that it has loaded but then I'd be worried about sticking IE into a loop whilst it continously checked to see if it was going to load or not. I also don't know how to catch the error if it doesn't load at all.

Perhaps this goal more closer revolves around how best to program javascript for a conditionand proceed only if it exists without killing IE into a loop until it does. By loop I mean that I've seen JS that crashes Ie by just looping on a condition that never becomes true or changes. The browser does nothing except run round the loop and dies. Maybe a properly/cleverly constructed loop to monitor the condition can be used but I am unsure of the best way to proceed on doing this.

Thanks for the reply lets hope someone can help kill two problems with one answer here eh.

brothercake
11-27-2002, 05:38 PM
Funny that .. because I couldn't use the onload solution either, for exactly the same reason.

The problem is that, as far as I can discover, there is no 5.0 compatibile property to indicate if a document inside an iframe has finished loading.

You know what I did? I abandoned the whole IFRAME paradigm, and used PHP to write the data into a textarea, then used javascript to read the data back and process/format it.

MattyUK
11-27-2002, 07:02 PM
For me that would be a whole new language to unpack and get to grips with. Planned to tackle it but not for this project. Thanks for your replies and ideas.

I'm not ready to give up yet. Anybody else any other ideas.

Let me rephrase the questions:

If I program a loop to read the text file (above posts) loaded in an IFRAME, how do I get it to:
1> Continue the loop without ERROR or NULL until the file loads?
2> Recognise if the IFRAME hits a 404 error and loads up the default "page cannot be displayed" page, and then abort.
3> Not kill the browser in checking the loop until the text file loads (not even sure that it would but it is just something I have heard).
4> All above for IE5.00.

Anybody?? Pretty please....


:confused: MattyUK

Vladdy
11-27-2002, 07:24 PM
If you could elaborate on what is that you are trying to do by reading a text file in the IFRAME.
It seems to me the sooner you start looking for other approaches the better of you are.

MattyUK
11-28-2002, 10:08 AM
That makes sense.

Well I am building an HTML app that is later packaged into an EXE. The app looks within the EXE for all the files except a text file which contains branding information. Currently I set the main page within the EXE to have an IFRAME that loads the text file, then just javascript to read the content of the file to a variable which I then split into a data array. The data array is then inserted via DHTML into the rendered page replacing default content/branding info.

I could not find any other way of opening the file and getting its contents other than use of the IFRAME. The function that reads the contents, parses the data and inserts is fired by the onload event of the IFRAME.

Obviously this works well with IE5.5 and not IE5.00 most of the clients I am targeting have left eth default IE5.00 on their system.

Hope the clears the picture a little

Vladdy
11-28-2002, 01:29 PM
If you could format your branding information into a js string:

Whatever string you have in your text file ->
brand='Whatever string you have in your text file';

The following code works fine with all DOM compliant browsers (IE 5+, Gecko based)

scriptNode=document.createElement('script');
scriptNode.type='text/javascript';
script.src = 'brand.js';
document.getElementsByTagName('head')[0].appendChild(scriptNode);


I bet this would simplify your js code as well

MattyUK
11-29-2002, 07:25 PM
It would. There are still some elements to play with. I need to parse the string into 5 sections using a seperator. That shouldn't present a problem (I can do that) I need it to fail withou error if there is no file to load. JS does and I can use an IF statement to decide if it has loaded. The only thing slightly wrong with the approach is that it allows the users to place valid JS and other script code into the file, this I'd need to prohibit. Also with JS code there (even simple JS code) they stand more chance of mucking it up. Whereas with plain text I felt I could escape easily. Still your idea is a good one and I think I can get close enough to what I need with it. Thank you.

MattyUK

Sorry for the delay in replying.