“Using Javascript to Write Javascript” By Nash R. Radovanovic Web Techniques, Sept 1997 Web Techniques grants permission to use these listings for private or commercial use provided that credit to Web Techniques and the author is maintained within the comments of the source. For questions, contact editors@web-techniques.com. SCRIPT JUNKIE LISTING ONE <html> <body bgcolor="#FFFFFF"> <SCRIPT LANGUAGE="JavaScript"> function opendemo() { window.open("struct.htm","demo","location=no,width=630, height=350,toolbar=no,directories=no,status=yes,menubar=n , scrollbars=no"); } </SCRIPT> <br><br><br> <center> To demonstrate dynamic <b>JavaScript</b> <i>InterNote</i> book, please click on button ! <br><br><br> <form method="get"> <input type="submit" name="goahead" value="Web Techniques Demo" onClick="opendemo()"> </form> </center> </body> </html> LISTING TWO <html> <title>BGD Consulting: Web Techniques Demo</title> <frameset rows="350,1,*" border=0> <frameset cols="70,230,82,230,70,*" border=0> <frame name="nl" src="nl.htm" scrolling="no" noresize border="0" marginheight="0" marginwidth="0"> <frame name="tl" src="tl.htm" noresize border="0" marginheight="0" marginwidth="0"> <frame name="bn" src="bn.htm" scrolling="no" noresize border="0" marginheight="0" marginwidth="0"> <frame name="tr" src="tr.htm" noresize border="0" marginheight="0" marginwidth="0"> <frame name="nr" src="nr.htm" scrolling="no" noresize border="0" marginheight="0" marginwidth="0"> </frameset> <frame name="drive" src="drive.htm" scrolling="no" noresize border=0> </frameset> <noframes> You need a forms capable browser to view this site ! </html> LISTING THREE <html> </html> LISTING FOUR <html> <title>Web Techniques: JavaScript Demo</title> <body leftmargin='0' topmargin='0' rightmargin='0' botmargin='0' bgcolor=Ō#FFFFFFÕ> <img src="gifs/bn.gif" width="70" height="350" alt="Binder" border="0"> </body> </html> LISTING FIVE <html> <title>Web Techniques: JavaScript Demo</title> <head> <script language="JavaScript"> <!---set background colors for all text pages---> function backgcol(tc) { if (tc == 1) { return "#FFCCCC";} if (tc == 2) { return "#C8E3FF";} if (tc == 3) { return "#FFFFC1";} if (tc == 4) { return "#FFBDFF";} if (tc == 5) { return "#2BFF95";} if (tc == 6) { return "#FFFFFF";} return "#FFFFFF"; } <!---set text content for all text pages---> function pagecontent(tc) { if (tc == 1) { return "Welcome to the <b>SERVICES</b> page !";} if (tc == 2) { return "Read <b>ABOUT</b> this demo !";} if (tc == 3) { return "You can <b>SEARCH</b> here !";} if (tc == 4) { return "Have a great <b>LINKS</b> today !";} if (tc == 5) { return "You can always <b>eMAIL</b> us !";} if (tc == 6) { return "This is your <b>unique</b> <br>opportunity to leave the <i><b>programming</b></i>to the browser.<br><br>Sit back and enjoy <b>:-)</b>!";} } <!---draw appropriate left tabs---> function writenl(left1,left2,left3,left4,left5,left6) { parent.nl.document.open("text/html"); parent.nl.document.write("<html><body bgcolor='#FFFFFF'>"); if (left1 == 1) { parent.nl.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(1); return true;'><img src='gifs/services.gif' border=0 width='60' height='58'></a>"); } else { parent.nl.document.write("<img src='gifs/blul.gif' border=0 width='60' height='58'>"); } if (left2 == 1) { parent.nl.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(2); return true;'><img src='gifs/about.gif' border=0 width='60' height='58'></a>"); } else { parent.nl.document.write("<img src='gifs/blml.gif' border=0 width='60' height='58'>"); } if (left3 == 1) { parent.nl.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(3); return true;'><img src='gifs/search.gif' border=0 width='60' height='58'></a>"); } else { parent.nl.document.write("<img src='gifs/blml.gif' border=0 width='60' height='58'>"); } if (left4 == 1) { parent.nl.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(4); return true;'><img src='gifs/links.gif' border=0 width='60' height='58'></a>"); } else { parent.nl.document.write("<img src='gifs/blml.gif' border=0 width='60' height='58'>"); } if (left5 == 1) { parent.nl.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(5); return true;'><img src='gifs/email.gif' border=0 width='60' height='58'></a>"); } else { parent.nl.document.write("<img src='gifs/blml.gif' border=0 width='60' height='58'>"); } if (left6 == 1) { parent.nl.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(6); return true;'><img src='gifs/home.gif' border=0 width='60' height='58'></a>"); } else { parent.nl.document.write("<img src='gifs/bldl.gif' border=0 width='60' height='58'>"); } parent.nl.document.write("</body></html>"); parent.nl.document.close(); } <!---draw appropriate right tabs---> function writenr(right1,right2,right3,right4,right5,right6) { parent.nr.document.open("text/html"); parent.nr.document.write("<html><body bgcolor='#FFFFFF'>"); if (right1 == 1) { parent.nr.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(1); return true;'><img src='gifs/servicer.gif' border=0 width='60' height='58'></a>"); } else { parent.nr.document.write(" <img src='gifs/blur.gif' border=0 width='60' height='58'>"); } if (right2 == 1) { parent.nr.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(2); return true;'><img s˙c='gifs/aboutr.gif' border=0 width='60' height='58'></a>"); } else { parent.nr.document.write("<img src='gifs/blmr.gif' border=0 width='60' height='58'>"); } if (right3 == 1) { parent.nr.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(3); return true;'><img src='gifs/searchr.gif' border=0 width='60' height='58'></a>"); } else { parent.nr.document.write("<img src='gifs/blmr.gif' border=0 width='60' height='58'>"); } if (right4 == 1) { parent.nr.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(4); return true;'><img src='gifs/linksr.gif' border=0 width='60' height='58'></a>"); } else { parent.nr.document.write("<img src='gifs/blmr.gif' border=0 width='60' height='58'>"); } if (right5 == 1) { parent.nr.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(5); return true;'><img src='gifs/emailr.gif' border=0 width='60' height='58'></a>"); } else { parent.nr.document.write("<img src='gifs/blmr.gif' border=0 width='60' height='58'>"); } if (right6 == 1) { parent.nr.document.write("<a href='drive.htm' target='drive' onClick='parent.drive.writetr(6); return true;'><img src='gifs/homer.gif' border=0 width='60' height='58'></a>"); } else { parent.nr.document.write("<img src='gifs/bldr.gif' border=0 width='60' height='58'>"); } parent.nr.document.write("</body></html>"); parent.nr.document.close(); } function writetr(textpage) { <!---create right text frame---> parent.tr.document.open("text/html"); parent.tr.document.write("<html> <title>Web Techniques: JavaScript Demo</title>"); parent.tr.document.write("<head><\script>"); <!---enable right text frame to create left text frame---> parent.tr.document.write("parent.tl.document.write(\"<html>\");"); parent.tr.document.write("parent.tl.document.write (\"<body leftmargin='0' topmargin='0' link='#000080' vlink='#0000FF' alink='#FF00FF' text='#000000' bgcolor='" + parent.drive.backgcol(textpage) + "'>\");"); parent.tr.document.write("parent.tl.document.write(\"</body></html> \");"); parent.tr.document.write("parent.tl.document.close();"); parent.tr.document.write("</\script></head>"); parent.tr.document.write("<body leftmargin=0 topmargin=0 link=#000080 vlink=#0000FF alink=#FF00FF text=#000000 bgcolor=" + parent.drive.backgcol(textpage) + ">"); <!---your predefined page content is being used here---> parent.tr.document.write("<br><br><br><br><center><font size='-1'>"); parent.tr.document.write(pagecontent(textpage)); parent.tr.document.write("</font></center>"); <!---draw appropriate left and right buttons---> parent.tr.document.write("<\script>"); if (textpage == 1) { parent.tr.document.write("parent.drive.writenr(1,1,1,1,1,1);"); parent.tr.document.write("parent.drive.writenl(0,0,0,0,0,0);"); } if (textpage == 2) { parent.tr.document.write("parent.drive.writenr(0,1,1,1,1,1);"); parent.tr.document.write("parent.drive.writenl(1,0,0,0,0,0);"); } if (textpage == 3) { parent.tr.document.write("parent.drive.writenr(0,0,1,1,1,1);"); parent.tr.document.write("parent.drive.writenl(1,1,0,0,0,0);"); } if (textpage == 4) { parent.tr.document.write("parent.drive.writenr(0,0,0,1,1,1);"); parent.tr.document.write("parent.drive.writenl(1,1,1,0,0,0);"); } if (textpage == 5) { parent.tr.document.write("parent.drive.writenr(0,0,0,0,1,1);"); parent.tr.document.write("parent.drive.writenl(1,1,1,1,0,0);"); } if (textpage == 6) { parent.tr.document.write("parent.drive.writenr(1,1,1,1,1,1);"); parent.tr.document.write("parent.drive.writenl(0,0,0,0,0,0);"); } parent.tr.document.write("</\script>"); parent.tr.document.write("</body></html>"); parent.tr.document.close(); } <!---...and start with the Home Page---> writetr(6); </script> </head> </html>