Search code examples
internet-explorerwebbrowser-controlactivexobject

Embed webbrowser control inside IE


How can I create a web browser activeX object inside a HTML document that is being opened with IE?

I have tried something like this, but the object did not display:

<object id="mini" width=300 height=300 classid="CLSID_WebBrowser"</object> ...

Solution

  • According to MSDN, since IE6 you should use an iframe instead: https://msdn.microsoft.com/en-us/library/aa752044%28v=vs.85%29.aspx

    That said, the following "works" for me in IE11. You have to specify the value of CLSID_WebBrowser:

    <object classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2" id="browser" width="600" height="600" />
    

    You can then do e.g.

    document.getElementById("browser").navigate("http://www.example.com")
    

    Edit: However, after the first navigate, any other method calls or property accesses result in "access denied". This is apparently by design: https://support.microsoft.com/en-us/kb/176789

    Then IE crashes when I close it so YMMV. I think the lesson here is that this isn't supported and you probably shouldn't be doing it.