我有一個htmlString。我將該字符串放入iframe中。 代碼是在插入DOM之前操縱html字符串
var iframe = document.createElement('iframe');
var html = '<html> <head></head> <body> //contents </body> </html>';
document.body.appendChild(iframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(html);
iframe.contentWindow.document.close();
現在我想要做的就是插入一個標籤
<base href="some url" >
到htmlString的頭。然後我想將iframe附加到dom中並將htmlString寫入該iframe。
如何在插入iframe之前修改htmlString?
儘管這樣更乾淨,更自然,但在將字符串插入iframe之前不會操縱字符串。 –