Sanitizer:setComments() 方法

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

Sanitizer 介面的 setComments() 方法用於設定清理器是否允許或移除註釋。

此方法會設定此清理器配置中的 comments 屬性。

語法

js
setComments(allow);

引數

allow

如果允許註釋,則為 true;如果移除註釋,則為 false

返回值

無 (undefined)。

示例

如何清理註釋

下面的程式碼展示了 setComments() 方法的基本用法。

js
// Create sanitizer (in this case the default)
const sanitizer = new Sanitizer();

// Allow comments
sanitizer.setComments(true);

// Remove comments
sanitizer.setComments(false);

規範

規範
HTML Sanitizer API
# dom-sanitizer-setcomments

瀏覽器相容性