focus method
[This documentation is preliminary and is subject to change.]
Causes the element to receive the focus and executes the code specified by the onfocus event.
![]() |
Syntax
object.focus()Standards information
- Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5
Parameters
This method has no parameters.
Return value
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Remarks
This method raises the onfocus event. The effect depends on the object calling the method. When called for child windows (such as those created with the open method of a window object), focus brings the target window to the foreground.
Elements cannot receive focus until the document finishes loading.
Windows Internet Explorer 8 and later. The focus method no longer brings child windows (such as those created with the open method) to the foreground. Child windows now request focus from the user, usually by flashing the title bar. To directly bring the window to the foreground, add script to the child window that calls the focus method of its window object.
Windows Internet Explorer 7 and later. For security reasons, child windows will only respond to the focus method when the following conditions are true:
- The child window does not have multiple tabs open.
- The focus method was not triggered by a double-click action.
If any of these conditions are true, the child window ignores the focus event.
As of Microsoft Internet Explorer 5, elements that expose the focus method must have the TABINDEX attribute set.
Build date: 3/8/2012
IE8 and later ..." add script to the child window that calls the focus method of its window object."
- 1/8/2010
- Remo Imparato
- 7/29/2010
- Mr. Raymond Kenneth Petry
Choice A. Top-Left, to show the cursor blinking at the Left of the Top text [non-absolute-position text];
Choice B. Top-Right, to show the Top-edge (scrollTop=0) and the Right-edge (scrollLeft=maximum);
N.B. #1. Choice A. declares the same scroll-variables as Choice B., just not the same scroll-position.
N.B. #2. This method results in the scroll-position jumping erratically while clicking or grabbing the scrollbar ... until the selected text reappears, or the scroll-variables are set. (Test case CONTENTEDITABLE)
REMEDY: Grab the scroll-variables before using textrange.select() or focus() -and- yank the scroll-variables afterward to their saved values.
__
CAUTION #2. If called from an element event handler (Test case onmousedown) with UNSELECTABLE=true, this method cannot pull focus from the in-chrome Location bar to another element, (yet it can pull focus from the Find Dialog box and other selectable elements).
__
N.B. #3. Despite focus, The in-chrome Find Dialog loses contact with reality upon reloading oContent from localStorage.
- 7/23/2010
- Mr. Raymond Kenneth Petry
- 7/29/2010
- Mr. Raymond Kenneth Petry
However when I tested the same on vista business SP1 32 bit and IE8 8.0.6001.18813. It behaves as mentioned in the post.
- 7/9/2010
- Suresh Thakur
- 4/17/2009
- george_5154
