簡體   English   中英

javascript動態創建iframe,但我如何追加屬性呢?

[英]javascript dynamic creation iframe, but how do I append attributes as well?

我已經編寫了一些代碼來動態創建iframe,如下例所示:

http://jsfiddle.net/xMakG/1/

但我有一個問題。 這些屬性似乎沒有附加到iframe。 例如,我寧願沒有iframe的邊框。 如果我沒有動態地執行此操作,那么只應用屬性就沒有問題了:

<iframe src="../Images/somethingpretty.png" name="frame1" id="frame1" onload="frameOnLoad()" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" allowtransparency="true"></iframe>

這只是按預期工作。 但是,我必須誤解某些內容或錯誤地指定javascript中的屬性。

似乎沒有附加的是:

src, onload, frameborder, marginwidth and marginheight, scrolling and allow transparency. 

奇怪的nameid工作正常。

我究竟做錯了什么?

使用.setAttribute 例如:

newFrame.setAttribute("onload", function(){});
newFrame.setAttribute("frameborder", 0);
newFrame.setAttribute("marginwidth", 0);
newFrame.setAttribute("marginheight", 0);
newFrame.setAttribute("scrolling", "auto");
newFrame.setAttribute("allowtransparency", true);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM