您可以將response.text()
渲染爲(如果您願意,可以使用visibility: hidden
)。然後你就可以與所有的標準功能,操作新的文檔:
<!DOCTYPE html>
<html>
<head>
<title>This is the page title</title>
<meta charset="UTF-8">
<meta name="description" content="Free Web Help">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
<meta charset="utf-8">
</head>
<body>
</body>
<script>
var img = new Image();
img.src = "http://cdn.sstatic.net/stackoverflow/img/[email protected]";
document.body.appendChild(img);
fetch("so.html")
.then(function(response) {
return (response.text());
})
.then(function(responseText) {
// limit the recursion depth to 1
if (!window.frameElement) {
var newDoc = document.createElement('iframe');
document.body.appendChild(newDoc);
newDoc.contentDocument.write(responseText);
}
});
</script>
</html>
自己試用,您可以將此代碼保存爲so.html
,並訪問您的本地Web服務器上,或者你可以check it out here。
如果您添加了「Javascript」標籤,您是否認爲您可能會從社區獲得更好的回覆? –
yeap。你是對的......)完成。 – jack
@Kkinsey任何答覆我的問題btw? ;) – jack