0

The following script works as expected on JSFiddle, but when I copy the script out and put it in a .html file locally it no longer works. The hyperlinks for the Reports no longer appear.

below is the script I'm saving to a .html file, which should be a copy of what's in JSFiddle link above.

<html>
<meta http-equiv="Content - Language" content="en - gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Report Menu</title> 
<style fprolloverstyle>A:hover {color: red; font-weight: bold} 
</style> 
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
function getMonthString(num) {

    var month; //Create a local variable to hold the string
    switch (num) {
        case 0:
            month = "01";
            break;
        case 1:
            month = "02";
            break;
        case 2:
            month = "03";
            break;
        case 3:
            month = "04";
            break;
        case 4:
            month = "05";
            break;
        case 5:
            month = "06";
            break;
        case 6:
            month = "07";
            break;
        case 7:
            month = "08";
            break;
        case 8:
            month = "09";
            break;
        case 9:
            month = "10";
            break;
        case 10:
            month = "11";
            break;
        case 11:
            month = "12";
            break;
        default:
            month = "13";
    }
    return month;
};
var d = new Date();
var name = 'Report_';
var name2 = 'Report_';

name += d.getFullYear();
name += getMonthString(d.getMonth());
name += d.getDate() - 1;
name += '.pdf';

name2 += d.getFullYear();
name2 += getMonthString(d.getMonth());
name2 += d.getDate() - 2;
name2 += '.pdf';

document.getElementById('lnk').innerText = name;

document.getElementById('lnk').setAttribute('href', name)

document.getElementById('lnk2').innerText = name2;

document.getElementById('lnk2').setAttribute('href', name2)
}//]]> 

</script>

</head>
<body>
  <title>Report Menu</title>
</head>
<body LEFTMARGIN="150">
    <table height=1 align="Right">
         <Font Size="1"> <font face='Mylius Sans'color= 999999 >This menu last refreshed: 10Aug15 02:19</font> 
    </table>
    <p><font face="Arial" size="3"><B>Daily_Network_Operations_Report</B></p><p><font size="2">Choose your report:</font>

    </p>
    <table border="0" cellpadding="2" cellspacing="5"><font size="2">
<tr><a href='#' id="lnk"></a></tr>
<tr><a href='#' id="lnk2"></a></tr>




</table>
<p><font face="Arial" size="1">earlier reports may be available - please email </p>
</body>



</html>
MrPaul91
  • 57
  • 5

3 Answers3

2

Add

<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 

at the start of your tag (by the way, you are missing the start tag.

The problem is that it's probably going into compatibility mode for whichever zone you are running it under.

potatopeelings
  • 40,709
  • 7
  • 95
  • 119
1

Even if the question have been answered I would like to add something that was pointed out by Altay Mazlum. This code is not working under Firefox (in my case at least).

You have to replace innerText by textContent.

Response from this thread ('innerText' works in IE, but not in Firefox) by Prakash K:

Firefox uses the W3C-compliant textContent property.

Community
  • 1
  • 1
0

Try to put your script at end of body tag:

<script src="script.js"></script>

Working Plunker

Not working Plunker

Another solution. Using onload at body tag:

DEMO

Manwal
  • 23,450
  • 12
  • 63
  • 93