This is because of two things: CHM uses the IE engine to render the pages. This means that the limitations of IE are also the limitations of your CHM. This includes problems with CSS and, sometimes, scripts.
Also, when you use RoboHelp 8, the webhelp uses the XHTML 1.0 transitional standard. This forces IE in a strict rendering mode. In the CHM, the pages use the HTML 4.01 frameset standard, putting IE in a different rendering mode (IE 5.5). This means that your scripts have to be compatible with a IE 5.5 rendering mode.
If you change your script so it will work with CHM, it should also work for WebHelp.