QuickHTML

From Team Developer SqlWindows Wiki
Jump to: navigation, search

QuickHTML


Contents


Pointer2.png cQuickHTML & Webbrowser: using document compatibility modes (IE7..IE11) Pointer.png


From MSDN:


Document compatibility defines how Windows Internet Explorer renders your web pages.
Windows Internet Explorer supports document compatibility modes that affect the way web pages are interpreted and displayed.
These modes, also called document modes, allow you to choose between support for the latest standard
or support for certain behaviors popularized by older browsers.

There a mainly two ways to display (HTML) web pages in a TD application:


  • Using cQuickHTML control (found in qwax.apl)
  • Using Microsofts webbrowser control (IE) (found in Microsoft Internet Controls ActiveX generated library)


You will have to know that cQuickHTML is using the Microsoft (IE) webbrowser control under the hood.
So, this article applies to both the TD control and the Microsoft one.


By default, the controls use the default compatibility view mode, which is basically document mode 7 (IE 7).
This means that HTML pages are rendered using the features of IE7 document mode.


You might encounter issues when showing pages in the control when it uses features which need a more modern IE version.
For instance, JavaScript could fail, events are not processed correctly, popups are not displayed or pages are rendered incorrectly.
An example what could happen is failing JavaScript on a web page and will show an error like this:


IE ScriptError.png


In that case, the cQuickHTML/Webbrowser control should be instructed to use another document mode to render the page.
This can be done in two ways:


  • Using the Compatibility Meta Tag inside the HTML (X-UA-Compatible)
  • Setting the compatibility mode in the registry for your application


The easiest and best way is that the HTML itself contains the instruction which compatibility mode should be used.
When the page is being loaded, the control will use the needed mode accordingly.


An example how to set the mode to IE 9 in HTML :


<!DOCTYPE html>
<html>
 <head>
 <meta http-equiv="X-UA-Compatible" content="IE=9">
 </head>
 ...


For more info on document modes can be found on MSDN:


So when you are in control of the HTML yourself, for instance you create it dynamically or open a HTML file from disk, add the needed meta tag before displaying it in the control.
The sample supplied with this article shows an example of this. It loads a HTML file from disk, inserts the meta tag and then displays it.


But what to do when you are not in control of the HTML? For instance when loading a page from internet or display pages from intranet/enterprise locations?


In that case, Microsoft offers a way to set the default document mode to use in the registry.
It is set on application level, so the mode will be used based on process/application name.
It can be set for the current user or for the local machine.


The registry locations are:

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
   SOFTWARE
      Microsoft
         Internet Explorer
            Main
               FeatureControl
                  FEATURE_BROWSER_EMULATION
                     MyApplication.exe = (DWORD) 00009000

More info on this can be found on MSDN:


The mode set in the registry will be taken into account when cQuickHTML/Webbrowser control is created the first time in your running application.
So you are able to programmatically set the registry value before the control is created.
But be aware that when the control was created, changing the value will not be taken into account further on when creating the control again.
The application has to be restarted to be able to use a new setting.


Also be aware that the application could be unable to update the registry due to missing permissions.
Even on HKEY_CURRENT_USER, a group policy can be set to not allow adding/changing the registry value.


Use the sample provided here to see both implementations: using registry and/or using meta tags.


In the sample, the first screen let you specify the mode which is saved to the registry.
Select the mode from the combobox and this will add the running application name to the registry location.
Beware that when you run from TD IDE, the TD IDE application name must be used, eg cbi63.exe.
The sample will automatically detect if you run from exe or IDE and will use the correct application name.


Use the button to start the window having a cQuickHTML control which shows local HTML or opens a web page.
The local HTML contains jscript to display the used document mode. There you can inspect which mode is currently used.


CQuickHTML DocumentModeSample.png


The sample contains a few ready-to-use global functions which could be copied to your project:

  • PALGetCurrentApplicationName -> returns MyApp.exe or cbiXX.exe depending how you run (from exe or IDE)
  • PALRegistry_GetEmulationModeIE -> returns the doc mode for the running application in registry
  • PALRegistry_SetEmulationModeIE -> sets the doc mode for the running application in registry


Here you can download the sample:
Down.png WIKI_WebBrowser_DocModeVersion.zip