Funktion "is not defined" nach document.open()
chak
- javascript
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(" ", dayBgColor, dayFontColor, dayFontSize, dayFontType);
}
else
{
if (dayNumber > stop)
{
writeCell(" ", 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(" ", 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ä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
Fehlermeldung aus der Konsole:
Error: init is not defined
Source File:...calendar.js
Line: 46
Hmm, muss ich jetzt zählen?
calWinDoc=calendarWindow.document.open();
Meines Wissens hat document.open() keinen Rückgabewert folglich ist calWinDoc undefiniert du willst:
calWinDoc = calendarWindow.document;
Struppi.
calWinDoc = calendarWindow.document;
hm. stimmt.danke. ändert aber nichts.
init()
ist eine der sechs im script verwendeten Funktionen (Kalender(), writeHead(), writeCell(), writeBody() und colorMeNew()).
Wieso mag sie nicht mehr bekannt sein?
chak
init()
ist eine der sechs im script verwendeten Funktionen (Kalender(), writeHead(), writeCell(), writeBody() und colorMeNew()).
Wieso mag sie nicht mehr bekannt sein?
Keine Ahnung, aber was mir beim kurzen Überblick auffällt ist das der HTML Code den du schreibst absolut kaputt ist.
calWinDoc.write('<table border="3" cellpadding="1" cellspacing="1">');
calWinDoc.write('<tr><td>');
Erst eine Tabelle
calWinDoc.write('<form name="startDate"><table border="3" cellpadding="1" cellspacing="1">');
Noch eine Tabelle
writeHead(monthHeading, headBgColor, headFontColor, headFontSize, headFontType);
In der Funktion ist eine <head> Zeile, die gehört zwischen <html> und <body>
writeHead(monthHeading, headBgColor, headFontColor, headFontSize, headFontType);
Noch einen <head> es kann nur einen geben
(Du kannst <script...> durchaus auch in den body schreiben)
calWinDoc.write('</form></td></tr></table>');
calWinDoc.close();
Ich bin mir nicht sicher ob da nicht ein schliessende </table> fehlt. wo ist <body>? wo ist <html>?
Das ist alles sehr unübersichtlich, keine Ahnung ob da FF mit aus dem Tritt gerät.
Struppi.
Ach, hast recht.
Ich glaube, in diesem Fall ist es einfacher, das von Anfang an neu zu schreiben, als was Bestehendes umzuwandeln...
Danke jedenfalls.
Gruß Chak