TrustedTypePolicyFactory: getAttributeType() method

Baseline 2026
Newly available

Since February 2026, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Note: This feature is available in Web Workers.

Phương thức getAttributeType() của giao diện TrustedTypePolicyFactory cho phép các nhà phát triển web kiểm tra xem có yêu cầu Trusted Type cho một phần tử và thuộc tính không, và nếu có thì là loại nào.

Cú pháp

js
getAttributeType(tagName, attribute)
getAttributeType(tagName, attribute, elementNS)
getAttributeType(tagName, attribute, elementNS, attrNS)

Tham số

tagName

Một chuỗi chứa tên của thẻ HTML.

attribute

Một chuỗi chứa một thuộc tính.

elementNS Optional

Một chuỗi chứa không gian tên, nếu rỗng thì mặc định là không gian tên HTML.

attrNS Optional

Một chuỗi chứa không gian tên, nếu rỗng thì mặc định là null.

Giá trị trả về

Một chuỗi với một trong các giá trị:

  • "TrustedHTML"
  • "TrustedScript"
  • "TrustedScriptURL"

Hoặc, null.

Ví dụ

Trong ví dụ này, truyền phần tử <script> và thuộc tính src vào getAttributeType() trả về "TrustedScriptURL".

js
console.log(trustedTypes.getAttributeType("script", "src")); // "TrustedScriptURL"

Thông số kỹ thuật

Specification
Trusted Types
# dom-trustedtypepolicyfactory-getattributetype

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