window.confirm

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Window.confirm() はブラウザーへ任意のメッセージ付きのダイアログを表示し、ユーザーがダイアログを承認またはキャンセルするまで待機します。

ある条件下、例えばユーザーがタブを切り替えているときなどでは、ブラウザーがダイアログを実際に表示しないことや、ダイアログの承認やキャンセルを待機しないことがあります。

構文

js
confirm(message)

引数

message

確認ダイアログ内に表示したい文字列。

返値

論理型で、OK (true) とキャンセル (false) のどちらが選択されたかを示します。ブラウザーがページ内ダイアログを拒否している場合、常に false を返します。

js
if (window.confirm("Do you really want to leave?")) {
  window.open("exit.html", "Thanks for Visiting!");
}

は以下のようになります。

Firefox の confirm

注記

ダイアログボックスはモーダルウィンドウです。つまり閲覧者は、これを閉じないと他のプログラムのインターフェイスにアクセスできません。したがって、ダイアログボックス(もしくは、モーダルウィンドウ)を生成する関数を乱用するべきではありません。何にせよ、それ相応の 確認を目的としたダイアログボックスの使用を避けるべき 理由があります。

仕様書

Specification
HTML
# dom-confirm-dev

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
confirm

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

関連情報