473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to write a new iframe from inline JS?

ok
<img src="http://www.6park.com/enter2/av.gif" onload="document.write('an
iframe obj');">

First of all, it destroy the HTML page.

Secondly even if it does not destroy it, the iframe object will be within an
img tag.

How do I write a new iframe obj outside img tag?
Jul 23 '05 #1
6 12557


ok wrote:
<img src="http://www.6park.com/enter2/av.gif" onload="document.write('an
iframe obj');">

First of all, it destroy the HTML page.

Secondly even if it does not destroy it, the iframe object will be within an
img tag.

How do I write a new iframe obj outside img tag?


You can use the DOM to create an iframe dynamically with IE5+, Netscape
6+, Opera 7 and other DOM compliant browsers:

function createIframe (iframeName, iframeSrc) {
var iframe;
if (document.createElement && (iframe =
document.createElement('iframe'))) {
iframe.name = iframeName;
iframe.src = iframeSrc;
document.body.appendChild(iframe);
}
}

<img onload="createIframe('iframeName', 'whatever.html');"
src="whatever.gif" alt="what ever">

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
ok
> <img src="http://www.6park.com/enter2/av.gif" onload="document.write('an
iframe obj');">

First of all, it destroy the HTML page.

Secondly even if it does not destroy it, the iframe object will be within an img tag.

How do I write a new iframe obj outside img tag?


By the way, a plain IFRAME tag is not allowed anywhere in the html
Jul 23 '05 #3
"ok" <a@b.c> wrote in message news:<41******@news01.argolink.net>...
<img src="http://www.6park.com/enter2/av.gif" onload="document.write('an
iframe obj');">
This is a strange directive. What you are saying is that when the
image gets loaded from the server, you want run the function
document.write. Assuming for a moment that document.write might do
something valid, it would insert into the document the phrase 'an
iframe obj'. Document.write takes as input normal html.
You would expect something like:
document.write("<iframe src='myiframe.html'><\/iframe>");
However, this wouldn't work in your situation.

It would appear that you are trying to set a message in the page when
the loading of the image is complete.

First of all, it destroy the HTML page.
How true. Document.write is designed to be used as the html is being
constructed. Once a web browser see the </html> tag, you can no
longer use the document.write function.

How do I write a new iframe obj outside img tag?


I assumed you were using the image as a button and wrote the follow
code. When I wrote the code, I didn't realize that you where using
the onload event handler. I assumed onclick. To change to the onload
do something like:
<img src="http://www.6park.com/enter2/av.gif"
onload="insertIframe();">

Notice that I have a div where the iframe will be inserted.

I tested this with macos 10.2.6 with IE 5.2 and netscape 7.3.

Robert
insert.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>insert an iframe</title>

<script type="text/javascript">
function insertIframe ()
{
var node;
if (document.getElementById)
{
node = document.getElementById("iframediv");
if (node)
{
var myElement = document.createElement("DIV");
node.appendChild(myElement);

myElement.innerHTML =
"<iframe src='myiframe.html' " +
"width='400' height='160'></iframe> " ;
}
else
{
alert("The function insertIframe could not find " +
"the tag iframediv.");
return;
}
}
else
{
alert(" document.getElementByID failed. " );
return;
}

}
</script>
</head>
<body>
<p>Insert an iframe.
<br>
Don't forget to see what happens when you
press the button more than once.</p>
<form>
<input type="button"
name="activate"
value="insert the iframe"
onclick="insertIframe();">
<br>
</form>
<div id='iframediv'>
</div>
</body>
</html>

myiframe.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>this is myiframe</title>
</head>
<body>
<p>This iframe was inserted by innerHTML.
<br>
This is amazing!</p>
</body>
</html>
Jul 23 '05 #4
Robert wrote:
"ok" <a@b.c> wrote in message news:<41******@news01.argolink.net>...


<--snip-->
First of all, it destroy the HTML page.

How true. Document.write is designed to be used as the html is being
constructed. Once a web browser see the </html> tag, you can no
longer use the document.write function.


Yes you can.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Blank Test Page</title>
<style type="text/css">
</style>
<script type="text/javascript">
</script>
</head>
<body>
Body Text
</body>
</html>
<script type="text/javascript">
document.write('New Body Text')
</script>
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #5
Randy Webb <Hi************@aol.com> wrote in message news:<Xt********************@comcast.com>...
Robert wrote:
"ok" <a@b.c> wrote in message news:<41******@news01.argolink.net>...


<--snip-->
First of all, it destroy the HTML page.

How true. Document.write is designed to be used as the html is being
constructed. Once a web browser see the </html> tag, you can no
longer use the document.write function.


Yes you can.


So I see. Any utility in it? Why would I want to do this? Is it
really valid since there should be no tags nor data after the </html>
that I am aware?

This should suffice:
Once a web browser see the </html> tag, you should no
longer use the document.write function.
You can always use the document.write as the OP did, but it will not
likely yeild the results expected ;-).

Robert
Jul 23 '05 #6
Robert wrote:
Randy Webb <Hi************@aol.com> wrote in message news:<Xt********************@comcast.com>...
Robert wrote:
"ok" <a@b.c> wrote in message news:<41******@news01.argolink.net>...
<--snip-->
First of all, it destroy the HTML page.
How true. Document.write is designed to be used as the html is being
constructed. Once a web browser see the </html> tag, you can no
longer use the document.write function.


Yes you can.

So I see. Any utility in it? Why would I want to do this? Is it
really valid since there should be no tags nor data after the </html>
that I am aware?


No real utility in it, just a reality (most of the time), with ad
inserting servers that either prepend the ad code, or append it to the
document. In that event, you can end up with some really wierd things
before the DTD and after the initial </html> and no its nowhere close to
valid code.
This should suffice:
Once a web browser see the </html> tag, you should no
longer use the document.write function.
Yes, that suffices.
You can always use the document.write as the OP did, but it will not
likely yeild the results expected ;-).


How true :) Depending on who is predicting the expected results :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Chen | last post by:
I need to use iframe to create a floating frame. But the contents in the iframe is not a external html file. Rather, it will be dynamically created by jsp. How can I set the src attribute to a URL...
2
by: H.A.P | last post by:
hi I'm trying to change the size of an iframe. In the following page, how should I do it? <html> <head> <script language="javascript"> function resize_frm() {
3
by: Dany P. Wu | last post by:
Hi everyone, I am trying to create a site with pages containing iframes. This is the first time I've used inline frames and am still struggling with the concept. This site will have 10 pages...
9
by: Julia Briggs | last post by:
How do I construct a <iframe> or equivalent for FireFox/NS browsers, inside a screen centered <div> tag? Can it be done?
4
by: Keon | last post by:
Hoi Do someone know how i can make the background of a iframe transparancy? I already tried it with filter: Alpha(Opacity=50,); but it also make the text transperancy. do someone know how to...
2
by: ad | last post by:
What is the difference between iframe and frame? What is the situation to use iframe ?
1
by: bjorn2k | last post by:
Hi All, I'm working on a webpage. In this webpage i have an IFrame. I load html files in this I frame, but then i get those scrollbars which i want to get rid off. My Iframe has a fixed width....
2
by: zhanye815 | last post by:
This problem is this:a page is made up of frameset, but i can't visit the iframe(inline frame) of the frame in the framset.just like the frameset have 3 frames,the third frame have a iframe(inline...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.