Преобразовать это в document.write Альтернативное решение? - PullRequest
1 голос
/ 18 января 2020

Следующий скрипт хорошо работает на отдельной странице. Однако, при его внедрении, document.write вступает во владение, таким образом оставляя остальную часть страницы в забвение. Я хотел бы альтернативное решение для создания необходимых ссылок через переменные. У меня мало или совсем нет опыта, кроме document.write для подобных вещей. Любая помощь / руководство с благодарностью.

<script language="javascript" type="text/javascript">
Today = new Date();
TodayDay = Today.getDate();
TodayMon = Today.getMonth();
TodayYear = Today.getYear();
if (TodayYear < 2000) TodayYear += 1900;
escNextYear = TodayYear;
escTwoYears = TodayYear;

if (TodayMon == 0) { TodayMonth = "January"; escNextMonth = "February"; escTwoMonths = "March"; } 
else if (TodayMon == 1) { TodayMonth = "February"; escNextMonth = "March"; escTwoMonths = "April"; }
else if (TodayMon == 2) { TodayMonth = "March"; escNextMonth = "April"; escTwoMonths = "May"; }
else if (TodayMon == 3) { TodayMonth = "April"; escNextMonth = "May"; escTwoMonths = "June"; }
else if (TodayMon == 4) { TodayMonth = "May"; escNextMonth = "June"; escTwoMonths = "July"; }
else if (TodayMon == 5) { TodayMonth = "June"; escNextMonth = "July"; escTwoMonths = "August"; }
else if (TodayMon == 6) { TodayMonth = "July"; escNextMonth = "August"; escTwoMonths = "September"; }
else if (TodayMon == 7) { TodayMonth = "August"; escNextMonth = "September"; escTwoMonths = "October"; }
else if (TodayMon == 8) { TodayMonth = "September"; escNextMonth = "October"; escTwoMonths = "November"; }
else if (TodayMon == 9) { TodayMonth = "October"; escNextMonth = "November"; escTwoMonths = "December"; }
else if (TodayMon == 10) { TodayMonth = "November"; escNextMonth = "December"; escTwoMonths = "January"; }
else if (TodayMon == 11) { TodayMonth = "December"; escNextMonth = "January"; escTwoMonths = "February"; }
else { TodayMonth = TodayMon; }
if (TodayMon == 11) {escTwoYears = TodayYear+1};
if (TodayMon == 11) {escNextYear = TodayYear+1};
if (TodayMon == 10) {escTwoYears = TodayYear+1};
escdate = TodayMon+1 + "/01/" + TodayYear;
escNextMon = TodayMon+2 + "/01/" + TodayYear;  //Vinnie
if (escNextMon > 12) {escNextMon = escNextMon - 12};
escTwoMon = TodayMon+3;
if (escTwoMon > 12) {escTwoMon = escTwoMon - 12};
escdatenext = escNextMon + "/01/" + escNextYear;
escdatetwo = escTwoMon + "/01/" + escTwoYears;

// document.write(escdate);

// document.write(TodayMonth + " " + TodayDay + ", " + TodayYear);
html = '<center>Please click on the month to view<br />the Professional Development Calendar for<br />' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escdate + '&location=2464" target="_blank"><strong>' + TodayMonth + '</strong></a>, ' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escNextMon + '&location=2464" target="_blank"><strong>' + escNextMonth + '</strong></a>, and ' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escdatetwo + '&location=2464" target="_blank"><strong>' + escTwoMonths + '</strong></a>' + 
'<p><div style="border: 3px solid rgb(201, 0, 1); overflow: hidden; margin: 15px auto; max-width: 736px;">' + 
     '<iframe scrolling="yes" src="https://www.escweb.net/ar_esc/catalog/coopcalendar.aspx?location=2464&mode=weekly" style="border: 0px none; height: 600px; width: 100%;"></iframe>'; 

document.write(html);

</script>

1 Ответ

1 голос
/ 18 января 2020

Похоже, причина того, что ваша страница переводится в "забвение", в том, что есть HTML теги, которые не закрываются. Попробуйте это:

html = '<center>Please click on the month to view<br />the Professional Development Calendar for<br />' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escdate + '&location=2464" target="_blank"><strong>' + TodayMonth + '</strong></a>, ' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escNextMon + '&location=2464" target="_blank"><strong>' + escNextMonth + '</strong></a>, and ' +
    '<a href="https://www.escweb.net/ar_esc/catalog/calendar.aspx?monthly&date=' + escdatetwo + '&location=2464" target="_blank"><strong>' + escTwoMonths + '</strong></a>' + 
    '<p><div style="border: 3px solid rgb(201, 0, 1); overflow: hidden; margin: 15px auto; max-width: 736px;">' + 
    '<iframe scrolling="yes" src="https://www.escweb.net/ar_esc/catalog/coopcalendar.aspx?location=2464&mode=weekly" style="border: 0px none; height: 600px; width: 100%;"></iframe>' +
    '</div></p></center>'; 
...