This question has a reference to the solution posted here. https://stackoverflow.com/a/2600261/5086633
I am facing similar issue in IE but even after adding much delay 200
this is not working as expected in my application. The input box gets focused only intermittently, it skips to focus on the input field even after the page gets rendered in IE. I also tried calling the setTimeout
function from $(document).ready(function(){
and $(window).load(function() {
as specified below with no success.
This code works fine when I test it locally and as a plain html file but not in my application.
Could anyone help me fix /or provide a clue to debug/ this issue in IE, so that input field gets the focus each time the page is rendered in IE?
Footnote:- It is working fine in Firefox (without delay) and in Chrome small delay is required for focus
to work.
$(document).ready(function(){
setTimeout(function() { document.getElementById('testfocus').focus(); }, 200);
});
$(window).load(function() {
// executes when complete page is fully loaded, including all frames, objects and images
setTimeout(function() { document.getElementById('testfocus').focus(); }, 200);
});
setTimeout(function() { document.getElementById('testfocus').focus(); }, 200);
<html>
<head>
</head>
<body>
<input id="testfocus"/>
</body>
</html>