Element: securitypolicyviolation イベント

Baseline Widely available

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

securitypolicyviolation イベントは、コンテンツセキュリティポリシーに違反したときに発生します。

イベントはポリシーに違反した要素で発行され、バブリングします。 通常は Window または Document オブジェクトのイベントハンドラーによって処理されます。

ハンドラーは onsecuritypolicyviolation プロパティを使用するか、EventTarget.addEventListener() を使用して割り当てることができます。

メモ: このイベントのハンドラーは最上位のオブジェクト(WindowDocument など)に追加する必要があります。 HTML 要素にプロパティが存在する間は、要素が読み込まれるまでプロパティにイベントハンドラーを割り当てることはできません。

構文

このイベント名を addEventListener() 等のメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。

js
addEventListener("securitypolicyviolation", (event) => {});

onsecuritypolicyviolation = (event) => {};

イベント型

下記コードは onsecuritypolicyviolation グローバルイベントハンドラープロパティ、または addEventListener() を使用して、イベントハンドラー関数を最上位の Window に追加する方法を示しています(Document でも全く同じ手法を使用することができます)。

js
window.onsecuritypolicyviolation = (e) => {
  // Handle SecurityPolicyViolationEvent e here
};

window.addEventListener("securitypolicyviolation", (e) => {
  // Handle SecurityPolicyViolationEvent e here
});

仕様書

Specification
Content Security Policy Level 3
# eventdef-globaleventhandlers-securitypolicyviolation
HTML
# handler-onsecuritypolicyviolation

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
securitypolicyviolation event

Legend

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

Full support
Full support

関連情報