--- title: Window.focus() slug: Web/API/Window/focus tags: - API translation_of: Web/API/Window/focus ---

{{APIRef}}

概述

请求将窗口显示在前(靠近屏幕),这可能由于用户设置而失败,并且该窗口在方法返回之前不能保证会显示在最前.

语法

window.focus()

示例

if (clicked) { window.focus(); }

规范

Specification Status Comment
{{SpecName('HTML WHATWG','interaction.html#dom-window-focus','Window.focus()')}} {{Spec2('HTML WHATWG')}}  

{{ languages( { "ja": "ja/DOM/window.focus", "pl": "pl/DOM/window.focus" } ) }}