Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
When I load a HTML file in the web browser object that has an input text field, the field does not accept focus. The input field accepts focus when viewed in Firefox and IE 11. The HTML file is a page I wrote and is stored locally on my HD.

EDIT: I should have mention that the web browser object is in one application, which is built and then placed inside of another program's form using setParent. When the web browser object's application is ran outside of the second program, the text focus works, but when ran inside of the second program, the field focus doesn't work, and I can't enter any text. Also a side note is that when the first program is inside of the second program, any drop down menus don't work. I am currently using Windows 8.1.

What I have tried:

I have tried to auto-focus the input field, which works in FireFox and IE 11, but not the Web Browser Object.
Any help would be appreciated.
Posted
Updated 3-Feb-20 6:34am
v2

1 solution

As a solution to the following problem, please make sure that you have tried out the code listed below:
<!DOCTYPE html>
<html>
<body>

<p>In this example, the text field gets focus immediately after the document window has been loaded.</p>
 
<input type="text" id="myText" value="A text field">

<script>
window.onload = function() {
  document.getElementById("myText").focus();
};
</script>

</body>
</html>

Specifically, this code is working for me when opening HTML-document using Google Chrome Browser.

Also, there are the guidelines explaining how to set focus on a specific input field when page is loaded:

HTML DOM focus() Method
[^]
Tryit Editor v3.6[^]

Enjoy! :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900