Window: sự kiện languagechange

Baseline Widely available

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

The languagechange event is fired at the global scope object when the user's preferred language changes.

Cú pháp

Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc thiết lập thuộc tính trình xử lý sự kiện.

js
addEventListener("languagechange", (event) => { })

onlanguagechange = (event) => { }

Kiểu sự kiện

Một Event chung.

Event handler aliases

In addition to the Window interface, the event handler property onlanguagechange is also available on the following targets:

Ví dụ

You can use the languagechange event in an addEventListener method:

js
window.addEventListener("languagechange", () => {
  console.log("languagechange event detected!");
});

Or use the onlanguagechange event handler property:

js
window.onlanguagechange = (event) => {
  console.log("languagechange event detected!");
};

Đặc tả kỹ thuật

Specification
HTML
# event-languagechange
HTML
# handler-window-onlanguagechange

Tính tương thích trên trình duyệt

Xem thêm