CafeHey
CafeHey

Reputation: 5800

Javascript that creates an Iframe

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. ).

Upvotes: 1

Views: 436

Answers (2)

Fosco
Fosco

Reputation: 38526

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>

Upvotes: 1

hunter
hunter

Reputation: 63522

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

Upvotes: 2

Related Questions