I'm using an Ajax call to open a search box in the page and I want the focus to go to the box automatically.
So, in the httpObject.resp onseText, I tried sending the following in addition to the search box markup:
and, after writing the response using innerHTML, the originating Ajax function calls an eval function to enable the JavaScript, the critical line being:
It works in Firefox and Safari because they default to the window.setTimeo ut method. The problem is (as usual) Internet Explorer...
1. The JavaScript executes just fine - the focus goes to the search box - if I open the code of the search box directly as a page. I tried other ways of setting the focus which worked similarly but also failed similarly when using window.execScri pt.
2. I've tried other things in place of focus() and they all worked. A simple alert works, writing text to the box works but the focus is never set.
3. I found that if I included an alert in the eval function, the focus WOULD be set after I clicked OK. But that's clearly defeating the purpose of saving the user a click.
I doesn't actually bother me that IE users would get an inferior experience but this is such a curious problem I really want to know the answer.
Are there any IE experts here that can tell me?
So, in the httpObject.resp onseText, I tried sending the following in addition to the search box markup:
Code:
<script type="text/javascript">
document.getElementById('Message').focus();
</script>
Code:
if(script) (window.execScript) ? window.execScript(script) : window.setTimeout(script, 0);
1. The JavaScript executes just fine - the focus goes to the search box - if I open the code of the search box directly as a page. I tried other ways of setting the focus which worked similarly but also failed similarly when using window.execScri pt.
2. I've tried other things in place of focus() and they all worked. A simple alert works, writing text to the box works but the focus is never set.
3. I found that if I included an alert in the eval function, the focus WOULD be set after I clicked OK. But that's clearly defeating the purpose of saving the user a click.
I doesn't actually bother me that IE users would get an inferior experience but this is such a curious problem I really want to know the answer.
Are there any IE experts here that can tell me?
Comment