Fixed the Javascript error in IE8 and only use handler when needed