chak: Funktion "is not defined" nach document.open()

Beitrag lesen

Hallo,

Auf Grundlage des kalenders aus http://de.selfhtml.org/javascript/beispiele/monatskalender.htm
bastel ich gerade an einer Abwandlung.
Beim Klick auf einen Knopf geht ein Fenster auf, in dem zwei Kalender zur Auswahl von Start- und Enddatum stehen.
Beim Klick auf ein TagesDatum soll die gleiche Funktion wieder ausgeführt werden, um das document neu zu schreiben.
Ich kann ohne Probleme anhängend in das gleiche Fenster schreiben.
Benutze ich aber document.close() und danach document.open(),
sind die daraufhin aufgerufenen Funktionen lt. Firefox-js-Konsole unbekannt! Woran mag das liegen?

Fehlermeldung aus der Konsole:
--
Error: init is not defined
Source File:...calendar.js
Line: 46
--

Hier der Quelltext:

//  variables

var headFontType = "Verdana,Arial";
  var headFontSize = 3;
  var headFontColor = "#FFFF00";
  var headBgColor = "#000066";
  var dayFontType = "Verdana,Arial";
  var dayFontSize = 3;
  var dayFontColor = "#000000";
  var dayBgColor = "#D0F0F0";
  var sundayColor = "#E00000";
  var todayBgColor = "#FFFF00";
  var nameOfMonth;
  var currentDate;
  var month;
  var year;
  var day;
  var start;
  var stop;
  var thisMonth;
  var thisYear;
  var thisDay;
  var time;
  var calWinDoc;
  var calendarWindow;

//the main function
function Kalender (param) {

if(param == 'newWin'){
  calendarWindow = window.open("about:blank",'aWin' ,"width=450,height=300");
  calWinDoc=calendarWindow.document.open();
 }
 else{
  calendarWindow = self;
  calWinDoc=calendarWindow.document.open("text/html", "replace");
//  calWinDoc.write("<h1>lala</h1>");
//  calWinDoc.close();
//  return;
 }

init();
 calWinDoc.write('<table border="3" cellpadding="1" cellspacing="1">');
 calWinDoc.write('<tr><td>');

calWinDoc.write('<form name="startDate"><table border="3" cellpadding="1" cellspacing="1">');
   var monthHeading = nameOfMonth[month - 1] + " " + year;
  writeHead(monthHeading, headBgColor, headFontColor, headFontSize, headFontType);
  writeBody();
 calWinDoc.write('</form></td><td>');
   calWinDoc.write('<form name="endDate"><table border="3" cellpadding="1" cellspacing="1">');
   var monthHeading = nameOfMonth[month - 1] + " " + year;
 writeHead(monthHeading, headBgColor, headFontColor, headFontSize, headFontType);
  writeBody();
 calWinDoc.write('</form></td></tr></table>');
  calWinDoc.close();

}

//writes the head of the calendar table
function writeHead (monthName, bgCol, FontCol, fontSize, fontType) {
  calWinDoc.write('<head><script src="calendar.js" type="text/javascript"></script></head>');
  calWinDoc.write("<tr>");
  calWinDoc.write('<td align="center" colspan="7" valign="middle" bgcolor="' + bgCol + '" >');
  calWinDoc.write('<font size="' + fontSize + '" color="' + FontCol + '" face="' + fontType + '"><b>');
  calWinDoc.write(monthName);
  calWinDoc.write("</b></font></td></tr>");
  calWinDoc.write("<tr>");
  for (var i = 0; i <= 6; i++)
  {
    writeCell(day[i], bgCol, FontCol, fontSize, fontType);
  }
  calWinDoc.write("</tr>");
}

//writes the cells containing the day numbers
function writeCell (content, bgCol, FontCol, fontSize, fontType) {
  var Zelle=content;
  calWinDoc.write('<td align="center" valign="middle" bgcolor="' + bgCol + '" + >');
  calWinDoc.write('<a name="' + content + '" href="javascript:colorMeNew(' + content +');" + >');
  calWinDoc.write('<font size="' + fontSize + '" color="' + FontCol + '" face="' + fontType + '"><b>');
  calWinDoc.write(content);
  calWinDoc.write('</a>');
  calWinDoc.write("</b></font></td>");
}

//writes the body of the calendars
function writeBody(){
  var dayNumber = 1;
 for (var i = 0; i <= 5; i++)
  {
        calWinDoc.write("<tr>");
       for (var j = 0; j <= 5; j++)
       {
         if ((i == 0) && (j < start))
    {
            writeCell("&#160;", dayBgColor, dayFontColor, dayFontSize, dayFontType);
          }
    else
    {
     if (dayNumber > stop)
     {
              writeCell("&#160;", dayBgColor, dayFontColor, dayFontSize, dayFontType);
           }
           else
           {
              if ((year == thisYear) && (month == thisMonth) && (dayNumber == thisDay))
              {
       writeCell(dayNumber, todayBgColor, dayFontColor, dayFontSize, dayFontType);
      }
      else
      {
       writeCell(dayNumber, dayBgColor, dayFontColor, dayFontSize, dayFontType);
      }
      dayNumber++;
           }
         }
      }

if (dayNumber > stop)
   {
    writeCell("&#160;", dayBgColor, sundayColor, dayFontSize, dayFontType);
   }
   else
   {
         if ((year == thisYear) && (month == thisMonth) && (dayNumber == thisDay))
         {
           writeCell(dayNumber, todayBgColor, sundayColor, dayFontSize, dayFontType);
         }
         else
         {
     writeCell(dayNumber, dayBgColor, sundayColor, dayFontSize, dayFontType);
        }
   dayNumber++;
  }

calWinDoc.write("</tr>");
   }
   calWinDoc.write("</tr>");
   calWinDoc.write("</table>");
}//end writeBody

//initializes date stuff
function init(){
 currentDate = new Date();
 month = currentDate.getMonth() + 1;
 year =  currentDate.getYear();

if (year < 999)
 {
  year += 1900;
 }

nameOfMonth = new Array("Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli",
                          "August", "September", "Oktober", "November", "Dezember");
   day = new Array("Mo", "Di", "Mi", "Do", "Fr", "Sa", "So");

var now = new Date();
  thisMonth = now.getMonth() + 1;
    thisYear = now.getYear();
    if (thisYear < 999)
      thisYear += 1900;
  thisDay = now.getDate();
  time = new Date(year, month - 1, 1);
  start = time.getDay();

if (start > 0)
  {
   start--;
  }
  else
  {
   start = 6;
  }

stop = 31;
  if (month == 4 || month == 6 || month == 9 || month == 11)
  {
      --stop;
  }

if (month == 2)
  {
  stop = stop - 3;
  if (year % 4 == 0)
  {
        stop++;
       }
     if (year % 100 == 0)
     {
       stop--;
      }
     if (year % 400 == 0)
     {
       stop++;
       }
   }
  }//end init()

//stub
  function colorMeNew(content){
 Kalender(content);
  }

Btw: Die js-Konsole hustet auch vielfach:
---
Error: gViewSourceWithMain is not defined
Source File: chrome://viewsourcewith/content/viewsourcewithOverlay.js
Line: 284
--
sagt das jemandem etwas?

Danke
Chak