color
10-24-2003, 09:21 AM
Hi
I have a slight problem with the focus() function in MS 5. I'm developing a intranet application where a window opens a modal dialog using window.showModalDialog() .
The modal dialog contains an iframe, this iframe contains a page which <BODY> tag has an onload event handler calling a init() function. The function that is called in the onload sets the focus to a specific field using the document.getElementByID(name). focus(). This needs to be dynamic as the field might be different each time (the html is generated from an jsp),
This works perfect on IE 6, while in IE 5 it works perfect the first time the dialog is opened, but the second time a javascript error is displayed saying the field is hidden, disabled or unable to recieve the focus.
The problem has been fixed by changing the onload to " window.setTimeout('init()', 100);"
Which gives the impression the problem is that upon executing the onload, the page has not really finished loading yet and thus the focus function cannot be executed.
It would be interesting to know if someone has any clue as to why this problem might have occured. Judging from the HTML reference at
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/focus.asp
there should be no differences between IE 5 and IE 6. (The elements on the page that can receive the focus has an tabindex="0" attribute)
Also, from what I could understand the onload event of the body tag ( which supposedly is the same as a onload event on the window itself) only executes AFTER the page has been loaded. In this specific case it seems the onload event is executed before the page has finished loading.
Thanks,
Jorgen
I have a slight problem with the focus() function in MS 5. I'm developing a intranet application where a window opens a modal dialog using window.showModalDialog() .
The modal dialog contains an iframe, this iframe contains a page which <BODY> tag has an onload event handler calling a init() function. The function that is called in the onload sets the focus to a specific field using the document.getElementByID(name). focus(). This needs to be dynamic as the field might be different each time (the html is generated from an jsp),
This works perfect on IE 6, while in IE 5 it works perfect the first time the dialog is opened, but the second time a javascript error is displayed saying the field is hidden, disabled or unable to recieve the focus.
The problem has been fixed by changing the onload to " window.setTimeout('init()', 100);"
Which gives the impression the problem is that upon executing the onload, the page has not really finished loading yet and thus the focus function cannot be executed.
It would be interesting to know if someone has any clue as to why this problem might have occured. Judging from the HTML reference at
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/focus.asp
there should be no differences between IE 5 and IE 6. (The elements on the page that can receive the focus has an tabindex="0" attribute)
Also, from what I could understand the onload event of the body tag ( which supposedly is the same as a onload event on the window itself) only executes AFTER the page has been loaded. In this specific case it seems the onload event is executed before the page has finished loading.
Thanks,
Jorgen