How to add iframe dynamically using javascript?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amkohl
    New Member
    • Jul 2010
    • 10

    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.

    Code:
    <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><bo dy>....</html> wrapped inside the iframe tag as shown in the attached snapshot (makeframe.jpg) .

    Code:
    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 Files
    Last edited by gits; Jul 7 '10, 06:10 AM. Reason: added code tags
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    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

    Comment

    Working...