views:

48

answers:

2

Hello.

I was wondering how you use a javascript tag in HTML to create an Iframe.

I've see it around, for example the 'Share This' button that everyone wants in there site is a script tage that then turns it's self into an Iframe.

How do you do this. I would rather give the client a line of script as opposed to an Iframe tag (so I can host the script externally and do things like change the location of the embedded Iframe. ).

+3  A: 
document.createElement("iframe");

here's a good tutorial as well: http://www.eggheadcafe.com/community/aspnet/3/83909/how-to-createelementa-and-add-innertext.aspx

hunter
A: 

An IFrame is just an HTML tag like anything else, so the same code you would use to populate HTML somewhere works to create an iFrame.

<script type=text/javascript>
document.getElementById('someDiv').innerHTML = '<iframe src="whatever.com/" height= width=>';
</script>
Fosco