HTMLGeolocationElement: hàm khởi tạo HTMLGeolocationElement()

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

Hàm khởi tạo HTMLGeolocationElement() tạo một thực thể đối tượng HTMLGeolocationElement mới.

Cú pháp

js
new HTMLGeolocationElement()

Tham số

Không có.

Giá trị trả về

Một thực thể đối tượng HTMLGeolocationElement mới, nếu được trình duyệt sử dụng nội bộ.

Các nhà phát triển không thể sử dụng trực tiếp hàm khởi tạo HTMLGeolocationElement() để tạo một thực thể HTMLGeolocationElement mới: việc cố gắng làm như vậy sẽ dẫn đến lỗi "illegal constructor".

Ví dụ

Tạo một thực thể HTMLGeolocationElement mới theo cách lập trình

Để tạo một thực thể HTMLGeolocationElement mới theo cách lập trình, thay vì cố gắng sử dụng trực tiếp hàm khởi tạo, bạn sẽ tạo một thực thể phần tử <geolocation> mới bằng cách sử dụng Document.createElement():

js
const geo = document.createElement("geolocation");

Sau đó bạn có thể sử dụng nó bằng cách thêm vào DOM:

js
document.body.append(geo);

Thông số kỹ thuật

Specification
The HTML Geolocation Element
# dom-htmlgeolocationelement-constructor