jamescover
07-01-2004, 12:42 PM
Hi:
I'm still wrestling with the same problem:
Is there any way to pass a variable in a nested document.writeln() statement???
Example Script:
<script>
<!--
myImg=new Image()
myImg.src="http://www.ekigroup.com/javascript/Clipboard.jpg";
myImg="clipboard";
function passVar(){
document.open();
document.writeln("Your image name is " +myImg);
document.writeln("<script>");
document.writeln("<!--");
document.writeln("function showDoc(){");
document.writeln("myImg=\"clipboard\";");
document.writeln("document.open();");
document.writeln("document.writeln(\"Your image name is \" +myImg);");
document.writeln("document.close();");
document.writeln("}");
document.writeln("setTimeout(\"showDoc()\",5000);");
document.writeln("//-->");
document.writeln("<\/script>");
document.close();
}
//-->
</script>
<body onload="passVar();">
The second document output:
Your image name is clipboard
<script>
<!--
function showDoc(){
myImg="clipboard";
document.open();
document.writeln("Your image name is " +myImg);
document.close();
}
setTimeout("showDoc()",5000);
//-->
</script>
The third document output:
Your image name is clipboard
The above script works, but as you can see, I have to redeclare myImg. If I don't, the second time the script writes to the page, I get a js error:myImg is undefined.
I thought this would be a session variable, for lack of a better term. So why can't I carry the value to the third document without redeclaring it??? Any ideas???
-james
I'm still wrestling with the same problem:
Is there any way to pass a variable in a nested document.writeln() statement???
Example Script:
<script>
<!--
myImg=new Image()
myImg.src="http://www.ekigroup.com/javascript/Clipboard.jpg";
myImg="clipboard";
function passVar(){
document.open();
document.writeln("Your image name is " +myImg);
document.writeln("<script>");
document.writeln("<!--");
document.writeln("function showDoc(){");
document.writeln("myImg=\"clipboard\";");
document.writeln("document.open();");
document.writeln("document.writeln(\"Your image name is \" +myImg);");
document.writeln("document.close();");
document.writeln("}");
document.writeln("setTimeout(\"showDoc()\",5000);");
document.writeln("//-->");
document.writeln("<\/script>");
document.close();
}
//-->
</script>
<body onload="passVar();">
The second document output:
Your image name is clipboard
<script>
<!--
function showDoc(){
myImg="clipboard";
document.open();
document.writeln("Your image name is " +myImg);
document.close();
}
setTimeout("showDoc()",5000);
//-->
</script>
The third document output:
Your image name is clipboard
The above script works, but as you can see, I have to redeclare myImg. If I don't, the second time the script writes to the page, I get a js error:myImg is undefined.
I thought this would be a session variable, for lack of a better term. So why can't I carry the value to the third document without redeclaring it??? Any ideas???
-james