07-05-2005, 11:24 AM | #1 (permalink) |
Crazy
|
[javascript] - only renders the 2nd time you view the webpage
Hello,
I have a postnuke website that is displaying some straightforward HTML in a part of the page. The purpose of the code is to take today's date and convert it to another calendar type using some simple calculations. It will then generate a URL based on the date and present it as an a href link. The problem is that it only displays the URL the 2nd time you view the page. The first time you view the site it doesnt' display it, but if you click any link which loads the page again, or just hit reload, it does work fine. How can I solve this problem? The html code for displaying it is as follows: Code:
<script Language="JavaScript" src="/synaxarium/copticDate.js"></script> <script> <!-- relative path of files goes between the quotes below --> document.write("<a href=\"/page.php?synaxarium/" + CopticName[CopticMonth].toLowerCase() + "/day" + CopticDay + ".html\">") <!--document.write(Date + " - " + CopticDate)--> document.write(CopticDate) document.write("</a>") </script> the file copticDate.js is as follows: Code:
today = new Date(); week = today.getDay(); day = today.getDate(); imonth = today.getMonth(); iyear = today.getYear(); month = imonth+1; if (iyear <= 99) { year = iyear + 1900; } else if (iyear > 99) { year = iyear; } leapcheck1 = year % 4; leapcheck2 = year % 100; leapcheck3 = year % 400; if ((leapcheck1 != 0) || ((leapcheck2 == 0) && (leapcheck3 != 0))) { leap = false; } else if ((leapcheck1 == 0) || (leapcheck3 == 0)) { leap = true; } yearb = year + 1; leapcheck4 = yearb % 4; leapcheck5 = yearb % 100; leapcheck6 = yearb % 400; if ((leapcheck4 != 0) || ((leapcheck5 == 0) && (leapcheck6 != 0))) { leapb = false; } else if ((leapcheck4 == 0) || (leapcheck6 == 0)) { leapb = true; } WeekName = new Array(7); WeekName[0]="Sunday" WeekName[1]="Monday" WeekName[2]="Tuesday" WeekName[3]="Wednesday" WeekName[4]="Thursday" WeekName[5]="Friday" WeekName[6]="Saturday" CopticName = new Array(14); CopticName[1]="Tute" CopticName[2]="Babah" CopticName[3]="Hatour" CopticName[4]="Kiahk" CopticName[5]="Tubah" CopticName[6]="Amshir" CopticName[7]="Baramhat" CopticName[8]="Baramoudah" CopticName[9]="Bashans" CopticName[10]="Baounah" CopticName[11]="Abib" CopticName[12]="Misra" CopticName[13]="El-Nasi" MonthName = new Array(13); MonthName[1]="January" MonthName[2]="February" MonthName[3]="March" MonthName[4]="April" MonthName[5]="May" MonthName[6]="June" MonthName[7]="July" MonthName[8]="August" MonthName[9]="September" MonthName[10]="October" MonthName[11]="November" MonthName[12]="December" i = 1; count = 0; if (month != i) { do { if ((i == 1) || (i == 3) || (i == 5) || (i == 7) || (i == 8) || (i == 10) || (i == 12)) { count = count + 31; } else if ((i == 4) || (i == 6) || (i == 9) || (i == 11)) { count = count + 30; } else if ((i == 2) && !leap) { count = count + 28; } else if ((i == 2) && leap) { count = count + 29; } i++; } while (i < month) } count = count + day; g = 1; CopticMonth = 4; CopticDay = 23; CopticYear = year - 284; if (count != g) { do { CopticDay++; g++; if (CopticDay == 31) { CopticDay = 1; CopticMonth++; } if ((CopticMonth == 13) && (CopticDay == 6) && !leapb) { CopticDay = 1; CopticMonth = 1; CopticYear++; } else if ((CopticMonth == 13) && (CopticDay == 7) && leapb) { CopticDay = 1; CopticMonth = 1; CopticYear++; } } while (g < count) } Date = WeekName[week] + ", " + MonthName[month] + " " + day + ", " + year; CopticDate = CopticName[CopticMonth] + " " + CopticDay + ", " + CopticYear + " AM"; |
Tags |
2nd, javascript, renders, time, view, webpage |
|
|