javaScript function not called from IE8

i work on page there is problem to call the javascript function call…this page is working on all other browser
and even on IE 8 on the othere system but not work on the same system with IE8…here is my code.

<!doctype html>
<html>
	<head>
	<script >
function startTime() {
	
    var today = new Date();
    var hr = today.getHours();
    var min = today.getMinutes();
    var sec = today.getSeconds();
    ap = (hr < 12) ? "<span>AM</span>" : "<span>PM</span>";
    hr = (hr == 0) ? 12 : hr;
    hr = (hr > 12) ? hr - 12 : hr;
    //Add a zero in front of numbers<10
    hr = checkTime(hr);
    min = checkTime(min);
    sec = checkTime(sec);
    document.getElementById("clock").innerHTML = "<span>" +hr+ "</span>" + "<span>:</span> " + "<span>"+ "</span>"+"<span>"+min+"</span>" + "<span>:</span>" + "<span>"+ sec+"</span>" + "  " + ap;
    var time = setTimeout(function(){ startTime() }, 500);
}
function checkTime(i) {
    if (i < 10) {
        i = "0" + i;
    }
    return i;
}
	</script>
<style type="text/css">
.clockdate-wrapper {
	background-color: #333;
	padding: 0px;
	max-width: 350px;
	width: 100%;
	text-align: center;
	border-radius: 5px;
	margin: 0 auto;
	margin-top: 15%;
	
}
#clock {
	
	font-family: sans-serif;
	font-size: 40px;
	text-shadow: 0px 0px 1px #fff;
	color:blue;
	width: 300px;
	
	font-weight: 900;
	margin-left: 35px;
	margin-top: 40px;
}
#clock span {
	color: #888;
	text-shadow: 0px 0px 1px #333;
	font-size: 30px;
	position: relative;
	top: -3px;
	left: -4px;
	color:darkgreen;
	
	font-weight: 600px;
}
#date {
	letter-spacing: 6px;
	font-size: 14px;
	font-family: arial, sans-serif;
	color: #fff;
	margin-top: 30px;
}
</style>
	
	</head>

	<body >
   <table border="4">
   	<tr>
   		<td><div id="clockdate">
        <div id="clock"> </div>
        <div id="date"></div>
    </div></td>
    
   	</tr>
   	<script type="text/javascript">
	   
    window.onload=startTime();
    
	   </script>
   	
   </table>
    
      
      
   
</body>
</html>

Are you getting any error messages in your console? I don’'t have an IE8 instance I can test things with at the moment.

It looks like window.onload isn’t implemented in IE8, so the functions won’t run. Will need a bit of digging to understand what the alternative is. You may need to do a little feature detection.

This may help - https://stackoverflow.com/questions/886668/window-onload-is-not-firing-with-ie-8-in-first-shot

There is no Error in console and this programe is run successfully in Chrome and other browser even on other system in IE8 it will works but on the this system not working i there is some setting of browser something is blocking or some else i don’t understand

Maybe this will give a clue: https://stackoverflow.com/questions/886668/window-onload-is-not-firing-with-ie-8-in-first-shot

if this not implemented than why this is working on IE on system but not work in specific system…

You’re going to have to describe the systems you’re referring to, as I don’t think we can help diagnose things otherwise.

System is window 7 just like normal system the code is paste in notepad and run

If it works on other systems running the exact same browser then the problem is with your browser. Did you disable JavaScript?

Also, stop supporting IE8.

4 Likes

…is the right answer

Plz where I can check supporting Java script enable? And what u mean by stop support in i8? Plz explain

It is an obsolete browser. Microsoft themselves don’t support it any longer, why would anyone else?
People still using it are a tiny minority. Plus old unsupported browsers are a security risk to their users. As a developer, dropping support will help goad the die-hard users to finally give it up and move on to a modern browser. This in turn helps us all, so we no longer need to even think about supporting older browsers.

4 Likes

This. Not only that, it’s a major productivity leak, not only for yourself but others as well. The problem with supporting IE8 (or other tech no longer supported the industry) is that you suck peoples time. I’m not hating on you at all, I’m just informing you, but here are the facts:

  • This post has 137 views, meaning a lot of people wasted time reading about something that’s totally unsupported
  • It also has 13 replies, meaning people wasted energy responding to something that’s totally unsupported
  • You still haven’t solved it, meaning you’ll continue to waste both time and energy on something that’s totally supported.

IE8 is totally unsupported.

1 Like

Ok thnx for reply but my question is that why this is working on other systems which has also i8 this mean s that there is some setting issue for which I take help from this forum

I think that I’ve spotted the problem, and it’s all to do with the onload line.

window.onload=startTime();

When the startTime() function is executed, it returns undefined. When IE8 executes the line, it looks at you wanting to assign undefined to the onload event, and gives you an error:

SCRIPT16385: Not implemented
ie8-onload.html (85,5)

IE8 throws the error because assigning undefined to the onload event is not valid.

Other browsers execute the startTime() function, and then silently ignore the problem when undefined is returned from the function.

What should be done instead is to assign a function to the onload event, such as with:

window.onload=startTime;

That will have no error then.

Another solution to all of this is to remove the onload part and place the script at the end of the body (just before the tag. You can then execute the code from there without the onload part. That way the code gets to run even sooner, without needing to wait for the onload event to eventually occur.

...
  <script>
  startTime():
  </script>
</body>
</html>

Either of those two solutions will work better than what you currently started with.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.