从System.Windows.Forms.WebBrowser访问HTMLObjectElement失败

时间:2014-02-20 09:04:50

标签: javascript html .net svg webbrowser-control

此HTML基于之前找到的解决方案here:

<body>
<object data="C:\Dts\AipDirs\Eg\MarsOutputStore\_AD2_LFBD_000.svg" id="alphasvg" width="100%" height="100%" type="image/svg+xml"></object>
<script>
    var a = document.getElementById("alphasvg");

    alert (a); // Displays [object HTMLObjectElement] when page is loaded into IE on desktop, but [object] when loaded into System.Windows.Forms.WebBrowser

    // it's important to add an load event listener to the object, as it will load the svg doc asynchronously
    a.addEventListener("load",function(){

        alert ("in addEvenetListener for load");       

    },false);
</script>

当我将其加载到桌面上运行的IE(版本10)时,这可以正常工作。但是,当我将它加载到UserControl中的WebBrowser对象时,它不起作用 - 警报返回一个不同的对象(请参阅该行的注释)然后它会抱怨:

Object doesn't support property or method 'addEventListener'

为什么WebBrowser在桌面上的行为不像IE?

1 个答案:

答案 0 :(得分:1)

这似乎解决了这个问题:

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

WebBrowser和IE对Intranet文档有不同的默认兼容模式,我从本地文件系统加载HTML文件。也许这与它有关?