HTMLGeolocationElement: sự kiện promptdismiss

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Sự kiện promptdismiss của giao diện HTMLGeolocationElement được kích hoạt mỗi khi người dùng kích hoạt phần tử <geolocation> và đóng hộp thoại kết quả, bằng cách nhấn nút "đóng" hoặc phím Esc.

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("promptdismiss", (event) => { })

onpromptdismiss = (event) => { }

Kiểu sự kiện

Một Event.

Ví dụ

Sử dụng promptdismiss để phản hồi việc người dùng đóng lời nhắc quyền

Trong bản demo Bản đồ nhúng (mã nguồn) của chúng tôi, chúng tôi sử dụng trình xử lý sự kiện promptdismiss để phản hồi người dùng đóng lời nhắc quyền <geolocation>:

js
geo.addEventListener("promptdismiss", notifyUserRetrySelection);

Trong hàm notifyUserRetrySelection(), chúng tôi yêu cầu người dùng nhấn nút lần nữa và cho phép vị trí.

js
function notifyUserRetrySelection() {
  statusElem.textContent =
    'Please press the "Use location" button again and allow location for this site.';
}

Xem trang chính HTMLGeolocationElement để có hướng dẫn đầy đủ về ví dụ này.

Thông số kỹ thuật

Specification
The HTML Geolocation Element
# dom-inpagepermissionmixin-onpromptdismiss

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