开发者

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

I have written some code to dynamically create an iframe as in this example :

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

But I have a problem. The attributes do not seem to being attached to the iframe. For example I'd rather not have a border with the iframe. If I wasn't doing this dynamically I would have no problem in just applying the attributes so:

<iframe src="../Images/somethingprett开发者_StackOverflow中文版y.png" name="frame1" id="frame1" onload="frameOnLoad()" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" allowtransparency="true"></iframe>

And this just works as expected. However I must have misunderstood something or incorrectly specified the attributes in the javascript.

The ones that don't seem to get appended are:

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

Strangely name and id work OK.

What am I doing wrong?


Use .setAttribute. For example:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜