Blog 1

Random Talk on Random Thoughts

Fixed a JavaScript TypeError

| Comments |

Background

I included an image with changeable size in a post written about two months ago.

How/Why does this work?

  • In brief: View /javascripts/svg-resize-bar.js.
  • For details: click the hyperlink above.

Problem

</source> FF throws TypeError

When I browsed any pages except that post which contains the changeable SVG image, the above TypeError was thrown.

Solution

From the error message TypeError: bar is null and the filename svg-resize-bar.js on the right, an ordinary user who knows how to write if-else statements should be able to solve this in a few seconds: surround the part bar.onchange = function () { ... } by the if-else statement if (bar != null ) { ... }.

Comments