HTML5中字符串的编码/解码问题

问题描述 投票:0回答:1

我正在尝试在HTML浏览器中显示以下字符串,但是当浏览器在字符串中遇到诸如“”之类的自定义标签时,它会跳过该字符串。

我尝试了encodeURIComponent(),后来又尝试在我的HTML模板中对URIComponent进行解码,但是没有用。

我什至试图通过创建如下所示的PIPE来清理HTML,但没有运气。

transform(v: string): SafeHtml {
        return this._sanitizer.bypassSecurityTrustHtml(v);
    }

以某种方式,浏览器正在像字符串中那样跳过元素。

以下是字符串

“The endpoint is browser-based, rather than RESTful. Therefore it could 
     result in the following different scenarios,↵1. SUCCESS 
    (response_type=code)↵> redirect_uri?code=<authorization-code>&scope= 
    <resource-owner-approved-scopes>[&state=<state-provided-by-the-client>]."
javascript html typescript decode encode
1个回答
1
投票

切勿在innerHTML中插入文本;仅将HTML插入innerHTML

当今的浏览器具有textContent属性:

textContent
© www.soinside.com 2019 - 2024. All rights reserved.