Forum Moderators: open

Message Too Old, No Replies

How to write an iframe using Javascript?

         

irock

8:18 pm on Sep 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, right now, I used HTML to form an iframe, but I would like to use Javascript to do that.

Could anyone provide some simple code that I can follow when forming an iframe using Javascript?

Thanks!

tedster

3:16 am on Oct 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not following you here. Iframe IS an HTML element. You can use javascript document.write() to write any HTML you want into your document, but it is still HTML that creates the iFrame.

What am I missing?

irock

4:00 am on Oct 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are right.

I just don't know the syntax of document.write() to write an iframe.

Is it something like this?

document.write("<iframe src=blah.htm frameborder=0>");

Thanks!

ricfink

6:21 pm on Oct 1, 2003 (gmt 0)

10+ Year Member



Depending upon what you are trying to acheive there are other ways to create an iframe with javascript.

Using document.write is one way.

However, you can also create it using the document object model and the createElement method.
[document.createElement('iframe');]

Or - quicker and simpler than using the DOM - if you want to position the iframe somewhere in particular on the page, you can mark the spot with a div, create the iframe html code using javascript and then change the innerHTML property of the div to the html code for the iframe.
The iframe will then appear in that spot on the page.

I'm assuming you don't want the iframe to take up the whole page. Otherwise why not just link to the source.....

If you'd like a further explanation on any of these other possibilities I'll check this thread later on today.

rich

irock

7:02 pm on Oct 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually I only want to form an iframe for my thispage.htm so that rogue spiders won't be able to hit that page.

ricfink

9:12 pm on Oct 1, 2003 (gmt 0)

10+ Year Member



Please educate me...

What do you mean?