hasFocus method
Gets a value indicating whether the object currently has focus.
Syntax
var pfFocus = document.hasFocus();Parameters
- pfFocus [out, retval]
-
C++ A pointer to a Boolean that receives one of the following values. JavaScript Boolean. Returns one of the following values.
Return value
Type: Boolean
A pointer to a Boolean that receives one of the following values.Boolean. Returns one of the following values.trueDocument has focus.
falseDocument does not have focus.
Standards information
There are no standards that apply here.
Examples
The following example shows how to use the hasFocus method to determine if the document has focus.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/callerWithHasFocusEX1.html
<html> <head> <script type="text/javascript"> function fnCallDialog() { showModelessDialog("myDialogHasFocus.htm", window, "status:false;dialogWidth:300px;dialogHeight:300px"); } // Function displays the message DIV when the main document has focus function fnOpenMessage() { if (document.hasFocus()) { oMessageDiv.style.display = "block"; } } function fnCloseMessage() { oMessageDiv.style.display = "none"; } </script> </head> <body> <p> <input type="button" value="Display Modeless Dialog" onclick="fnCallDialog()"> </p> <p> <span style="color:darkmagenta;font-size:large;" onmouseout="fnCloseMessage();" onmouseover="fnOpenMessage();">Mouse over this!</span> <div id="oMessageDiv" style="display:none;width:200;font-family: arial;font-size:large; color: steelblue; border: 4 solid gold;"> A message for you! </p> </div> </body> </html>
See also
Show: