外部 URL へのリクエストを行う API テスト ツールを作成しています。
これらの外部 URL のほとんどは JSON を返しますが、HTML も返されることがあります。このような場合、レンダリングされた HTMl を表示したいと思います。
私の最初の解決策は、返された HTML を iFrame 内にレンダリングすることでした。
<script id="response-body-content" type="application/vnd.response-body">
<%= raw response_body.gsub("script", "xcriptx") %>
</script>
<iframe id="response-body-preview"></iframe>
<script>
$(function(){
var ifrm = document.getElementById("response-body-preview");
var ifrmDocument;
if(ifrm.contentWindow) {
ifrmDocument = ifrm.contentWindow.document
} else {
ifrmDocument = ifrm.contentDocument
}
ifrmDocument.open()
ifrmDocument.write($("#response-body-content").text().replace(/xcriptx/g, "script"));
ifrmDocument.close()
});
</script>
外部 HTML が my script タグ コンテナを壊さないように、iFrame に印刷するために、置き換えなければなりませんでしたscript
。*xscript*
#response-body-content
ページ内の (安全な) 外部 HTML を印刷/レンダリングする他の回避策はありますか?