Delphi TWebBrowser Wont Run Javascript from LocalHost

I have a really simple Delphi XE7 program. It is basically just a TWebBrowser component embedded in a form with no extra code attached, other than a button that fires off the Browser.Navigate method. My understanding is that TWebBrowser is just an ActiveX wrapper for IE.

I am trying to use this to display a very simple page that references the D3 Javascript library (but so far doesn't do anything with it), and the web pages are served from a localhost webserver that is running on my PC using WAMPSERVER.

The web pages run just fine in Chrome or IE 11 (I have Windows 7, 64 bit). But when I try to view them within the Delphi/TWebBrowser program I get the IE error message "An error has occurred on the script on this page" (see image attached). The error seems to occur when trying to access the d3.js javascript library in the d3test/d3 folder on the local host. I have verified that the d3.js file does exist in this folder and this seems to be borne out by the fact that the page runs and displays just fine in both Chrome and IE.

Perhaps there is an issue with having an embedded web browser access locally hosted pages? Additional background -I have also cleared the IE cache, reset the Internet options on the Windows Control Panel, set IE security settings to the minimum level and temporarily disable my Norton Firewall/Virus scanner.

Does anyone have any thoughts on this? I'm really hoping to be able to get some D3 charts embedded in my Windows-based program.

Here also is the html code:

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>D3 Test</title>
<script type="text/javascript" src="d3\d3.js"></script>
Hello World


I added answer from your comments below the question so its may helpful to others

add this meta tag into your web page

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

In this case you should add this class to your code:

type TBrowserEmulationAdjuster = class
      class function GetExeName(): String; inline;
   public const
      // Quelle:, Stand: 2017-04-26
      IE11_default   = 11000;
      IE11_Quirks    = 11001;
      IE10_force     = 10001;
      IE10_default   = 10000;
      IE9_Quirks     = 9999;
      IE9_default    = 9000;
      /// <summary>
      /// Webpages containing standards-based !DOCTYPE directives are displayed in IE7
      /// Standards mode. Default value for applications hosting the WebBrowser Control.
      /// </summary>
      IE7_embedded   = 7000;
      class procedure SetBrowserEmulationDWORD(const value: DWORD);
end platform;

class function TBrowserEmulationAdjuster.GetExeName(): String;
    Result := TPath.GetFileName( ParamStr(0) );

class procedure TBrowserEmulationAdjuster.SetBrowserEmulationDWORD(const value: DWORD);
const registryPath = 'Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION';
    registry:   TRegistry;
    exeName:   String;
    exeName := GetExeName();

    registry := TRegistry.Create(KEY_SET_VALUE);
       registry.RootKey := HKEY_CURRENT_USER;
       Win32Check( registry.OpenKey(registryPath, True) );
       registry.WriteInteger(exeName, value)


Finaly add to your OnCreate of the Form:


This should solve your problem

Need Your Help

New line character in excel when printing from string excel newline stringbuilder

I am trying to print a value to a cell that contains a line seperator like ALT+ENTER or Char(10). Everything so far just prints my text so that it prints the values I want to wrap in the excel are in

How can i deliver jetty with many webapps via jnlp?

jetty jnlp embedded-jetty java-web-start maven-jetty-plugin

i have a webapp ( wich use...