1

The CHM viewer on Windows 10 does not allow me to use the 'window' object in JavaScript, although on Windows 7 it works perfectly with the same version of Internet Explorer.

To reproduce this problem: Copy this code into a file 'index.htm'

<!DOCTYPE html>
<html>
<body>
    <script>
    document.write("Inner width: " + window.innerWidth + "<br>");
    try
    {
        window.addEventListener('scroll', function(e)
        {
            document.write("Scroll<br>");
        } );
        document.write("All right.<br>");
    }
    catch (ex)
    {
        document.write("Exception: " + ex.message + "<br>");
    }
    </script>
</body>
</html>

Then copy this code into a file 'Test.hhp'

[OPTIONS]
Binary Index=No
Compatibility=1.0
Compiled file=Test.chm
Default Window=>MainHelp
Default topic=index.htm
Display compile progress=Yes
Language=0x409 Englisch (USA)
Title=Testing

[WINDOWS]
>MainHelp="Testing",,,"index.htm",,,,,,0x40000,,0x0,[50,50,900,750],,,,,,,0

Copy both files into the same directory and compile them with the Html Help Workshop.

On Windows 7 it works as expected:

JavaScript can access window object in CHM file on Windows 7

On Windows 10 it works in Internet Explorer, but not in the CHM file:

JavaScript cannot access window object in CHM file on Windows 10

There seems to be a security restriction in Windows 10 which is not in Windows 7.

Is there any registry key or any Internet Explorer setting which I can modify to give the CHM viewer the permission to access the 'window' object ?


Edit: After reading the answer from Dai I found why it worked on Windows 7 and not on Windows 10. It has nothing to do with the Windows version. The reason is that on my Windows 7 another software already had set the registry key

[HKLM\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION]
hh.exe = 9000
Elmue
  • 5,679
  • 41
  • 53
  • The `window` object **does** exist (otherwise you wouldn't be getting the "Object doesn't support..." error), but the CHM viewer is running in IE compatibility mode so it's emulating IE7 which didn't have `addEventListener`. – Dai May 12 '20 at 16:55
  • Have you seen this article? https://weblog.west-wind.com/posts/2012/feb/15/make-your-chm-help-files-show-html5-and-css3-content – Dai May 12 '20 at 17:03
  • Hello Dai. Yes you are right: setting these registry keys solves the problem. But the solution from help-info.de is far easier. – Elmue May 12 '20 at 20:39

1 Answers1

2

I could reproduce this behavior on my German Windows10 PC.

Add the following statement to the <head> section of the index.htm file. This works for me even if the HTML topic file is compiled into a .chm help file.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE11"/>

e.g.:

<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE11"/> 
</head>

is resulting in following help viewer window:

enter image description here


Edit: A comprehensive answer related to x-ua-compatible was given on SO for following question:

What does <meta http-equiv="X-UA-Compatible" content="IE=edge"> do?

Quoted from Microsoft docs Use Enterprise Mode to improve compatibility:

If you don't have IE11 installed anymore, you can download it from the Internet Explorer 11 download page. Also, if you use an earlier version of Internet Explorer, upgrade to IE11. Windows 7, Windows 8, and Windows 10 support IE11 so that you can continue using legacy apps even as you migrate to Windows 10 and Microsoft Edge.

help-info.de
  • 5,228
  • 13
  • 34
  • 35
  • Do you know if it is OK to emulate IE 11 if for example IE 9 is installed? – Elmue May 12 '20 at 20:45
  • 1
    @Elmue Under what scenario today would someone have IE9 installed? – Dai May 12 '20 at 20:58
  • I wonder if this approach also works in HTA files too... I remember trying to get modern HTML5 features working in a HTA a few years ago and when I did used `IE=Edge` (rather than `IE=EmulateIE11`) it stopped the HTA extensions from working so my HTA's window icon and other settings stopped working. – Dai May 12 '20 at 21:00
  • @Elmue - you may try ` `to avoid a hard coded IE version (see my EDIT too). – help-info.de May 13 '20 at 07:54