@whitesev/pops
Version:
弹窗库,包含了alert、confirm、prompt、drawer、folder、loading、iframe、panel、tooltip、searchSuggestion、rightClickMenu组件
23 lines (22 loc) • 524 B
text/typescript
export const PopsSafeUtils = {
/**
* 获取安全的html
*/
getSafeHTML(text: string) {
if (window.trustedTypes) {
const policy = window.trustedTypes.createPolicy("safe-innerHTML", {
createHTML: (html: string) => html,
});
return policy.createHTML(text);
} else {
return text;
}
},
/**
* 设置安全的html
*/
setSafeHTML($el: Element, text: string) {
// 创建 TrustedHTML 策略(需 CSP 允许)
$el.innerHTML = this.getSafeHTML(text);
},
};