I have desgined a JS that will allow you to type in parameters for an applet and display it in an iframe (with the help of some of you in my targeting an iframe string). Currently all you should change are the first 2 colors (ca,cb/coloraa/colorbby) when playing with it. The code goes as follows:
------------------------------------------------------------------------
<script>
<!--hide
function dip() {
var ca;
var cb;
var frames;
var cs;
var neg;
var pos;
var speed;
var den;
ca="document.thing.coloraa.value";
ca="document.thing.colorbby.value";
ca="document.thing.frames.value";
ca="document.thing.cs.value";
ca="document.thing.neg.value";
ca="document.thing.pos.value";
ca="document.thing.speed.value";
ca="document.thing.den.value";
var oIFrame = document.getElementById('i'),
oFramedDoc = typeof oIFrame.contentDocument != 'undefined'?
oIFrame.contentDocument: // W3C way
typeof oIFrame.contentWindow != 'undefined'?
oIFrame.contentWindow.document: // Microsoft way
typeof oIFrame.document != 'undefined'?
oIFrame.document: // Traditional way
null; // And no way.
if(oFramedDoc != null){
oFramedDoc.open();
oFramedDoc.write('<applet code="Wave" width="300" height="150" alt="Wave applet" align="center" vspace="5"><param name="color1" value="'+ca+'"><param name="color2" value="'+cb+'"> <param name="frames" value="'+frames+'"> <param name="colors" value="'+cs+'"> <param name="neg" value="'+neg+'"> <param name="pos" value="'+pos+'"> <param name="speed" value="'+speed+'"> <param name="density" value="'+den+'"></applet>') }
}
//--></script>
</head><body bgcolor=royalblue>
<iframe ID="i" width=307 height=157></iframe>
<form name="thing" onSubmit="dip()">
<input type=text size=22 name="coloraa" value="enter hex code here">
<input type=text size=22 name="colorbby" value="enter hex code here">
<input type=text size=22 name="frames" value="32">
<input type=text size=22 name="cs" value="256">
<input type=text size=22 name="neg" value="2">
<input type=text size=22 name="pos" value="2">
<input type=text size=22 name="speed" value="50">
<input type=text size=22 name="den" value="100">
<input type=submit value="Make Applet Happen" style="border-style:ridge" style="border color:blue" style="background-image:URL(g7.bmp)" style="color:aqua;font-weight:bold;font-style:italic">
</form>
-------------------------------------------------------------------------------
I can't fiqure out why it won't work. Any ideas?
Willy Duitt 02-01-2004, 07:28 PM For one, you keep changing the value of ca:
eg:
ca="document.thing.coloraa.value";
ca="document.thing.colorbby.value";
ca="document.thing.frames.value";
ca="document.thing.cs.value";
ca="document.thing.neg.value";
ca="document.thing.pos.value";
ca="document.thing.speed.value";
ca="document.thing.den.value";
And the values of neg, pos, speed and den are undefined.
<param name="neg" value="'+neg+'">
<param name="pos" value="'+pos+'">
<param name="speed" value="'+speed+'">
<param name="density" value="'+den+'">
Try something like this:
neg="document.thing.neg.value";
.....Willy
Yeah, I figured out the "ca" thing about an hour after I posted. Now it looks like this:
<script type="text/javascript" language="Javascript">
<!--hide
function dip() {
var ca="document.thing.coloraa.value";
var cb="document.thing.colorbby.value";
var frames="document.thing.frames.value";
var cs="document.thing.cs.value";
var neg="document.thing.neg.value";
var pos="document.thing.pos.value";
var speed="document.thing.speed.value";
var den="document.thing.den.value";
var oIFrame = document.getElementById('i'),
oFramedDoc = typeof oIFrame.contentDocument != 'undefined'?
oIFrame.contentDocument: // W3C way
typeof oIFrame.contentWindow != 'undefined'?
oIFrame.contentWindow.document: // Microsoft way
typeof oIFrame.document != 'undefined'?
oIFrame.document: // Traditional way
null; // And no way.
if(oFramedDoc != null){
oFramedDoc.open();
oFramedDoc.write('<applet code="Wave" width="300" height="150" alt="Wave applet" align="center" vspace="5"><param name="color1" value="'+ca+'"><param name="color2" value="'+cb+'"> <param name="frames" value="'+frames+'"> <param name="colors" value="'+cs+'"> <param name="neg" value="'+neg+'"> <param name="pos" value="'+pos+'"> <param name="speed" value="'+speed+'"> <param name="density" value="'+den+'"></applet>') }
}
//--></script>
</head><body bgcolor=royalblue>
<iframe ID="i" width=307 height=157></iframe>
<form name="thing" onSubmit="dip()">
<input type=text size=22 name="coloraa" value="hex code here, please">
<input type=text size=22 name="colorbby" value="hex code here">
<input type=text size=22 name="frames" value="32">
<input type=text size=22 name="cs" value="256">
<input type=text size=22 name="neg" value="2">
<input type=text size=22 name="pos" value="2">
<input type=text size=22 name="speed" value="50">
<input type=text size=22 name="den" value="100">
<input type=submit value="Make Applet Happen" style="border-style:ridge" style="border color:blue" style="background-image:URL(g7.bmp)" style="color:aqua;font-weight:bold;font-style:italic">
</form>
After changing it, there is still an error.
Basscyst 02-01-2004, 10:00 PM Hello -
Not sure if this will fix the problem but I see:
var oIFrame = document.getElementById('i'),
There shouldn't be a comma at the end there should there?
Bassscyst
Basscyst 02-01-2004, 10:57 PM I believe so, yes.
liorean 02-01-2004, 11:00 PM Basscyst: It should be a comma, not a semicolon. (I should know, I wrote it (http://codingforums.com/showthread.php?s=&postid=166829) for him.)
It is more clear with original formatting, however:
var
oIFrame = document.getElementById('i'),
oFramedDoc = typeof oIFrame.contentDocument != 'undefined'?
oIFrame.contentDocument: // W3C way
typeof oIFrame.contentWindow != 'undefined'?
oIFrame.contentWindow.document: // Microsoft way
typeof oIFrame.document != 'undefined'?
oIFrame.document: // Traditional way
null; // And no way.
Bobo: Hmm, what is the error? Where in the code? May it have something to do with that you write only an applet element and not a whole document to the iframe?
The error once said syntax, and I don't even get one anymore, so it probably is the lack of an entire document like stated. It should work as just the applet, though, because when you first helped me with that code I successfully used it to test HTML/Javascript without having to re-load. The problem is that I don't know where in the code the error is or even what it is anymore.
liorean 02-01-2004, 11:59 PM Try this:
function dip(){
var
ca=document.thing.coloraa.value,
cb=document.thing.colorbby.value,
frames=document.thing.frames.value,
cs=document.thing.cs.value,
neg=document.thing.neg.value,
pos=document.thing.pos.value,
speed=document.thing.speed.value,
den=document.thing.den.value,
oIFrame=document.getElementById('i'),
oFramedDoc = (typeof oIFrame.contentDocument != 'undefined')?
oIFrame.contentDocument: // W3C way
(typeof oIFrame.contentWindow != 'undefined')?
oIFrame.contentWindow.document: // Microsoft way
(typeof oIFrame.document != 'undefined')?
oIFrame.document: // Traditional way
null; // And no way.
if(oFramedDoc != null){
oFramedDoc.open();
oFramedDoc.write('<applet code="Wave" width="300" height="150" alt="Wave applet" align="center" vspace="5"><param name="color1" value="'+ca+'"><param name="color2" value="'+cb+'"> <param name="frames" value="'+frames+'"> <param name="colors" value="'+cs+'"> <param name="neg" value="'+neg+'"> <param name="pos" value="'+pos+'"> <param name="speed" value="'+speed+'"> <param name="density" value="'+den+'"></applet>');
}
}
glenngv 02-02-2004, 03:11 AM The error was specifically on the quotes:
var ca="document.thing.coloraa.value";
as what liorean fixed.
Now I have like this:
<script type="text/javascript">
<!--hide
function dip(){
var
ca=document.thing.coloraa.value,
cb=document.thing.colorbby.value,
frames=document.thing.frames.value,
cs=document.thing.cs.value,
neg=document.thing.neg.value,
pos=document.thing.pos.value,
speed=document.thing.speed.value,
den=document.thing.den.value,
oIFrame=document.getElementById('i'),
oFramedDoc = (typeof oIFrame.contentDocument != 'undefined')?
oIFrame.contentDocument: // W3C way
(typeof oIFrame.contentWindow != 'undefined')?
oIFrame.contentWindow.document: // Microsoft way
(typeof oIFrame.document != 'undefined')?
oIFrame.document: // Traditional way
null; // And no way.
if(oFramedDoc != null){
oFramedDoc.open();
oFramedDoc.write('<applet code="Wave" width="300" height="150" alt="Wave applet" align="center" vspace="5"><param name="color1" value="'+ca+'"><param name="color2" value="'+cb+'"> <param name="frames" value="'+frames+'"> <param name="colors" value="'+cs+'"> <param name="neg" value="'+neg+'"> <param name="pos" value="'+pos+'"> <param name="speed" value="'+speed+'"> <param name="density" value="'+den+'"></applet>');
}
}
//-->
</script>
</head><body bgcolor=royalblue>
<iframe ID="i" width=307 height=157></iframe>
<form name="thing" onSubmit="dip()">
<input type=text size=22 name="coloraa" value="color11">
<input type=text size=22 name="colorbby" value="anutter color22">
<input type=text size=22 name="frames" value="32">
<input type=text size=22 name="cs" value="256">
<input type=text size=22 name="neg" value="2">
<input type=text size=22 name="pos" value="2">
<input type=text size=22 name="speed" value="50">
<input type=text size=22 name="den" value="100">
<input type=submit value="Make Applet Happen" style="border-style:ridge" style="border color:blue" style="background-image:URL(g7.bmp)" style="color:aqua;font-weight:bold;font-style:italic">
</form>
...and the iframe just comes up blank.
glenngv 02-03-2004, 01:53 AM Don't forget the document.close()
if(oFramedDoc != null){
oFramedDoc.open();
oFramedDoc.write('....');
oFramedDoc.close();
}
Geez... it still comes up blank.:( All the coding seems correct and I don't get an error. Everything should work...:confused:
glenngv 02-03-2004, 03:11 AM try putting html and body tags.
if(oFramedDoc != null){
oFramedDoc.open();
oFramedDoc.write('<html><body><applet ....</applet></body></html>');
oFramedDoc.close();
}
If it still fails, try removing the oFramedDoc.open() line as oFramedDoc.write() automatically calls it.
BTW, what browser are you using? Does it have the required Java plugin installed? Does the applet work if the tags are hardcoded?
I tried the <HTML><BODY> thing with no success, so I'll try the oFramedDoc.open() and oFramedDoc.write() thing. I'm using a recent (not sure quite which) version of IE, that does support java. The applet works when it's hardcoded.
Well, I tried it only to be met by a blank iframe.
glenngv 02-04-2004, 01:41 AM Ok, try this:
<form name="thing" onSubmit="dip();return false">
And can you put this alert to check if the iframe reference is really not null?
if(oFramedDoc != null){
...
}
else alert("oFramedDoc is null!");
Okay, now the applet shows up and works in the iframe, however the applet uses the default parameters instead of the ones specified in the text boxes.
glenngv 02-04-2004, 05:40 AM What did you do? Can you show us the modified code? The applet uses the default param values maybe because the supplied values are invalid? Like the color params, I noticed you specify "color11" and "anutter color22". Are they valid values?
I did exactly as said a few posts up to no avail. The modified code is:
--------------------------------------------------------------------------------
<script type="text/javascript">
<!--hide
function dip(){
var
ca=document.thing.coloraa.value,
cb=document.thing.colorbby.value,
frames=document.thing.frames.value,
cs=document.thing.cs.value,
neg=document.thing.neg.value,
pos=document.thing.pos.value,
speed=document.thing.speed.value,
den=document.thing.den.value,
oIFrame=document.getElementById('i'),
oFramedDoc = (typeof oIFrame.contentDocument != 'undefined')?
oIFrame.contentDocument: // W3C way
(typeof oIFrame.contentWindow != 'undefined')?
oIFrame.contentWindow.document: // Microsoft way
(typeof oIFrame.document != 'undefined')?
oIFrame.document: // Traditional way
null; // And no way.
if(oFramedDoc != null){
oFramedDoc.open();
oFramedDoc.write('<HTML><HEAD> </head><body bgcolor=navy><applet code="Wave" width="300" height="150" alt="Wave applet" align="center" vspace="0" hspace="0"><param name="color1" value="'+ca+'"><param name="color2" value="'+cb+'"> <param name="frames" value="'+frames+'"> <param name="colors" value="'+cs+'"> <param name="neg" value="'+neg+'"> <param name="pos" value="'+pos+'"> <param name="speed" value="'+speed+'"> <param name="density" value="'+den+'"></applet></body></html>');
oFramedDoc.close();
}
else alert("oFramedDoc is null!");
}
//-->
</script>
</head><body bgcolor=royalblue>
<iframe ID="i" width=307 height=157></iframe>
<form name="thing" onSubmit="dip();return false">
<input type=text size=22 name="coloraa" value="#0000ff">
<input type=text size=22 name="colorbby" value="#00ffff">
<input type=text size=22 name="frames" value="32">
<input type=text size=22 name="cs" value="256">
<input type=text size=22 name="neg" value="2">
<input type=text size=22 name="pos" value="2">
<input type=text size=22 name="speed" value="50">
<input type=text size=22 name="den" value="100">
<input type=submit value="Make Applet Happen" style="border-style:ridge" style="border color:blue" style="background-image:URL(g7.bmp)" style="color:aqua;font-weight:bold;font-style:italic">
</form>-------------------------------------------------------------
I have had NO success so far.
Can anyone figure out the problem is?:confused:
Willy Duitt 02-07-2004, 08:13 PM At this point it probably would be best to publish the codes and
provide a link so someone could see the script actually run.
.....Willy
I don't have a site so here's a zip. You'll have to remove the page and class file from the zip and put them into a normal folder for them to function properly.
glenngv 02-16-2004, 01:19 AM Tested it in IE6 with Java plugin 1.4.1_01.
I got errors in Java Console:
Coudn't parsed color1.
Coudn't parsed color2.
Meaning the colors assigned to params color1 and color2 are invalid colors. I tried color names instead and the same error occured. I tried using the hex colors again but without the # symbol and it worked! :thumbsup:
Lesson: Check the Java Console.
THANKS GLENN!!:D Just one thing, though. This may sound like a newB question (and it is) but I have never heard of a java console. What is it?
glenngv 02-17-2004, 03:08 AM When you load a page with an applet, you will see the Java icon (that coffee icon) from the taskbar, if configured to be shown. If you are using IE, you can double-click that icon to open it or click Tools / Sun Java Console from the browser's menu bar. If you are using NS6+/Mozilla, it's in Tools / Web Development / Java Console.
Java console is used for debugging applets. Any System.out and System.err statements in the applet source code are displayed in the console.
More info here (http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/console.html).
|
|