View Full Version : focus() after document.write crashes IE (sometimes)

04-05-2003, 09:53 PM
I just spent 6 hours isolating the most obscure bug. The funny thing was that putting alert messages in the code to help find it (see how far I got through the code before it crashed) stopped it from occurring.

I'm using frames, and I use a frame called "create" to run things. "create" maintains variables and re-creates the page the users see, "image," as necessary to change the image they see.

To re-create it I call the function makeImage().

At the very end of makeImage(), after the document.write that actually re-creates the page, I do a focus() to place the cursor where I want it on the newly re-created page. The program runs without the focus(), but with it somewhat inconsistently IE crashes with the message "performed an illegal operation." Can't have that!

It seems -- just guessing here -- that when it crashes it might be trying to focus() on a page that isn't fully re-created yet. Doesn't exist yet. This could happen as the page can take some time to re-create. (This would explain why placing an alert message before the focus() stopped the problem from occuring... giving it more time.)

I need something like onDocumentDoneWriting.focus().

Thanks for any ideas, Peter

function makeImage(){

04-05-2003, 11:09 PM
In your string "c" where you define the body tag how about including an onload event handler to give the window focus?

04-05-2003, 11:15 PM
Thanks, but I don't understand what you mean.

Can you give an example of syntax? I'm not sure what should be "onloaded".

Actually, onload has puzzled me and I have never been able to make it work having tried for many different purposes over the last few years. Obviously I have trouble understanding it.

Thanks, Peter

04-06-2003, 12:55 AM
i think what he meant is add this to c

c="<html><body onLoad='document.f1.search.focus();'>";

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum