469,586 Members | 2,185 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,586 developers. It's quick & easy.

How to add iframe dynamically using javascript?

Hi All,

I need to add a dynamic iframe at page load using JS (like below just after the beginning of the <body> tag.

Expand|Select|Wrap|Line Numbers
  1. <iframe src="" HEIGHT=1 WIDTH=1 FRAMEBORDER=0></iframe>
The issue here is if I try to add iframe using document.write then it shows me the <html><head><body>....</html> wrapped inside the iframe tag as shown in the attached snapshot (makeframe.jpg).

Expand|Select|Wrap|Line Numbers
  1. document.write('<iframe frameborder="0" scrolling="no" height="300" width="300" name="askFrame" src=""></iframe>'); 
Can someone please share the code snippet of adding the same using JavaScript?

Thanks in advance!
Attached Images
File Type: jpg makeframe.jpg (12.6 KB, 233 views)
Jul 7 '10 #1
1 2683
607 512MB
Hi You have added iframe correctly. Iframe is a container in which you can load another html file. Inisde the Iframe it will have <html><head> everything. Since it is a place holder for another html page inside a html page.

Thanks and Regards
Ramanan Kalirajan
Jul 7 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by delraydog | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.