Why am I getting this Javascript runtime error?

I have the following javascript on my web page ...

64 var description = new Array(); 65 description[0] = "..." 66 description[1] = "..." ... 78 function init() { 79 document.getElementById('somedivid').innerHTML = description[0]; 80 } 81 82 window.onload = init(); 

The following error occurs in Microsoft Internet Explorer ...

Runtime Runtime Error.
Do you want to debug?

Line: 81
Error: not implemented

javascript runtime error

Line 79 is executed as expected.

If line 79 is commented out, it still throws an error.

If I comment on line 82, the function will not execute and there will be no error.

+4
source share
5 answers

Do not read line 82:

 window.onload = init; 

When you execute "init ()", it is a function call that returns void. You call this function before the page loads.

+13
source

To save any previously installed onload functions try this

 var prevload = window.onload; window.onload = function(){ prevload(); init(); } 
+2
source

Try adding an envent listener for "load" instead, or use the declarative syntax <body onload="init()"> .

EDIT: Also, saying window.onload = init(); set window.onload to the result of calling init() . You mean window.onload = init; (lambda expression). This is even worse as it overwrites other things that might be related to window.onload .

+1
source

In addition to the onload corrections offered here, also check if there are several elements with this ID, I believe that IE will return a collection of all elements with this identifier, in which case you will need to select the required element from the collection before accessing this property or make sure you use unique identifiers.

0
source

Try to run it in FireFox with the included FireBug plugin. This will allow you to debug javascript

0
source

Source: https://habr.com/ru/post/1277529/


All Articles