Common Code

Some JavaScript code is common to many routines.  Rather than repeat it in each JavaScript example, I present it here just once.

[Go Up to JavaScript index]

JavaScript

Common Start-of-Script

<script LANGUAGE="JavaScript"><!--

   (script goes here)

// -->
</script>

Include Common Functions in the <head> section of every page using this script:

<script src="http://mcraefamily.com/MathHelp/CommonScripts.txt"
   language
="JavaScript" type="text/javascript"></script>

// Common Data Structure Constructor, in CommonScripts.txt, which go in the <head>.

// a "vector" object has properties X and Y.
function vector(X, Y) {
   this.X = X;
   this.Y = Y;}

// Common HTML-builders, in CommonScripts.txt, which go in the <head>.

// table functions

function Htable() {
   var argv = Htable.arguments;
   var argc = argv.length;
   if (argc==0) {
      return "";}
   if (argc==1) {
      return "<table border=1 cellspacing=0 cellpadding=4>"
         + argv[0] + "</table>";}
   var x="";
   for (var i=1; i<argc; i++) {
      x = x + argv[i];
      }
   return "<table " + argv[0] + ">" + x + "</table>";
   }

function Hframe(t) {
   return Htable("border=10 cellspacing=0 cellpadding=4",Htr(Htd(t)));}

function Htr() {
   var argv = Htr.arguments;
   var argc = argv.length;
   var x = "";
   for (var i=0; i<argc; i++) {
      x = x + "<tr>" + argv[i] + "</tr>";}
   return x;}

function Htd() {
   var argv = Htd.arguments;
   var argc = argv.length;
   var x = "";
   for (var i=0; i<argc; i++) {
      var y = argv[i]+""=="" ? "&nbsp;" : argv[i]+"";
      x = x + "<td>" + y + "</td>";}
   return x;}

// Common Document Manipulation Functions, which go in the <head>

function BreakOutOfFrame() {
   // see http://www.thesitewizard.com/archive/framebreak.shtml
   if (top.location != location) {
      top.location.href = document.location.href ;
      }
   }

// Using the common functions in the <body>
<script language="JavaScript" type="text/javascript"><!--
BreakOutOfFrame();//-->
</script>