Windows Dev Center

EN
Dieser Inhalt ist in Ihrer Sprache leider nicht verfügbar. Im Folgenden finden Sie die englische Version.

hasFocus method

Gets a value indicating whether the object currently has focus.

Syntax

var pfFocus = document.hasFocus();

Parameters

This method has no parameters.

Return value

Type: Boolean

Boolean. Returns one of the following values.true

Document has focus.

false

Document 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.


<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

document

 

 

Anzeigen:
© 2015 Microsoft