我試圖動態創建iframe並在創建之前將其設置爲基本標記。設置動態創建的iframe的基本標記
ifrm = document.createElement("IFRAME");
ifrm.setAttribute("src", "test.html");
ifrm.style.width = 400+"px";
ifrm.style.height = 100+"px";
//before creating it, can we set he base tag?
//I.E. <base href="http://example.com/MyFolder/" />
var bt = ifrm.contentDocument.createElement("base");
bt.setAttribute("href", "http://www.example.com/Folder/");
ifrm.contentDocument.getElementsByTagName("head")[0].appendChild(bt);
document.body.appendChild(ifrm);
我知道我可以在iframes src文件本身設置基本標記。但我需要在這裏設置它。 謝謝。
我仍然無法得到這個工作。不知道該從哪裏出發。 – aquawicket