Object doesn't support property or method WebBrowser Control
Asked Answered
K

3

15

I have developed a mobile app (in asp.net) and I am using a WinForms application with the WebBrowser control to demo it.

I my main page I am using a script to hide the address bar:

<script type="text/javascript">
    window.addEventListener("load", function () {
        // Set a timeout...
        setTimeout(function () {
            // Hide the address bar!
            window.scrollTo(0, 1);
        }, 0);
    });
</script>

This has worked ok an several machines but this morning on a new machine I encountered an popup when the page loads:

enter image description here

The machine in question has IE9 installed and I have the Disable Script Debugging setting Checked.

What is the best way to tackle this issue. Can I add some condition in the JS to not execute when running in IE?

Kettle answered 31/8, 2012 at 13:25 Comment(1)
It would seem that the IE9 Tools>Options Settings are not used by the WebBrowser control. So even though Disable Script Debugging is checked in IE, this setting is not propagated to the control. I managed to switch this off in the control by using WebBrowser.ScriptErrorsSuppressed = TrueKettle
V
35

I know that this problem is from 2012 but there is an answer for it.

At the top of the <head> document where script is added you need to write

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

WinForms WebBrowser control is using Internet Explorer but you need to force the latest version there. For eg. if you are using jQuery 2+ it requires IE 9+ so you need to use at least version 9 or later.

Veracruz answered 16/1, 2015 at 7:52 Comment(1)
I am WinForm browser control and facing same problem. How do I handle from browser control?Brandenbrandenburg
C
2

Webbrowser control doesn't suppert jquery v2.

Use the jquery 1.9.1.

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
Canopus answered 2/2, 2016 at 8:29 Comment(0)
W
0

The Webbrowser control is a part of the Internet Explorer itself. And Internet Explorer doesnt support the window.addEventListener method. Use window.attachEvent method instead.

So the script in your page will read like

window.attachEvent("load", function () {
    // Set a timeout...
    setTimeout(function () {
        // Hide the address bar!
        window.scrollTo(0, 1);
    }, 0);
});

Hope this would help you!

Williwaw answered 31/8, 2012 at 13:33 Comment(1)
msdn.microsoft.com/en-us/library/ie/ff975245%28v=vs.85%29.aspx would suggest that IE9 does support addEventListener. Does the WebBrowser control use IE9 if it is installed?Kettle

© 2022 - 2024 — McMap. All rights reserved.