• 0

[VB.net] WebBrowser control does not load javascript


Question

Recommended Posts

  • 0

its not working on the proggie i made

You are going to have to learn to provide more data than that. Simply driving into a mechanics lot and saying; "There is a problem with my car" is not enough. Development work is about the TINY TINY details. Often it is best to give a sample of your code so others can reproduce the issue or see where you are making a mistake.

  • Like 2
Link to comment
Share on other sites

  • 0

its not working on the proggie i made

Right... we've established this from your first post; did you load up IE and check the settings in there to ensure it has JavaScript enabled in there as suggested?

Also try helping us to help you; put up some code samples so we can 'jump into' the code and locate any possible issues there?

We can really only help you if you're willing to help yourself, otherwise it's just us flogging the dead donkey while you play with yourself in the corner.

Link to comment
Share on other sites

  • 0

probably because you are using a local file. The standard security settings of IE disable javascript/activeX on local files. It could be that the webbrowser control does this too

Link to comment
Share on other sites

  • 0

http://www.jeffblankenburg.com/2010/10/18/31-days-of-windows-phone-day-18-webbrowser-control/

This page wil help you:

In case you?re planning on loading an HTML page that contains some JavaScript, you should know that scripting is disabled in the WebBrowser control by default. It?s simple to turn back on (or even toggle) using the IsScriptEnabled property of the control. Here?s two quick examples:

Link to comment
Share on other sites

  • 0

You are going to have to learn to provide more data than that. Simply driving into a mechanics lot and saying; "There is a problem with my car" is not enough. Development work is about the TINY TINY details. Often it is best to give a sample of your code so others can reproduce the issue or see where you are making a mistake.

Couldn't agree more...

Link to comment
Share on other sites

  • 0

And this is exactly why I said learn ABOUT programming, learn on smaller "hello world" projects and break things down rather than jump into a large project just using a drag-and-drop interface.

Link to comment
Share on other sites

  • 0

Doesnt its for C#

And your point is?

VB.Net

Browser.IsScriptEnabled = true

C#

Browser.IsScriptEnabled = true;

See how much trouble I had to go through to translate that from c# to vb. I'm tired now, I need a rest ;)

Seriously, as a developer, don't expect everything to be spelled out for you. Also, ditch VB.net its syntax is horrendous compared to c#

Link to comment
Share on other sites

  • 0

Doesnt its for C#

Dude offers you help. If you knew the first thing about the language you are "programming" (drag/dropping) in, you'd know C# and VB.net are easily substituted.

PLEASE I urge you to try and understand basic programming more before you write bad code into your app.

Link to comment
Share on other sites

  • 0

But I just realised you are probably making a desktop application. In that case the javascript is enabled by default and you don't have that property

Link to comment
Share on other sites

  • 0

Thanks!!!!

The only code there is webbrowser1.navigate "wherever.com" so I figured you guys knew that x

Here's another good point; In development NEVER (ever ever ever ever!) assume ANYTHING! (I'm not yelling at you, I am highlighting my point) It can be frustrating, but even a minor item can have a big effect. Development is about being very explicit. (as you are, I'm sure, quickly learning)

Have a good day.

Link to comment
Share on other sites

  • 0

And your point is?

VB.Net

Browser.IsScriptEnabled = true

C#

Browser.IsScriptEnabled = true;

See how much trouble I had to go through to translate that from c# to vb. I'm tired now, I need a rest ;)

Seriously, as a developer, don't expect everything to be spelled out for you. Also, ditch VB.net its syntax is horrendous compared to c#

Man I already tried that before posting my comment and it didnt work.

Link to comment
Share on other sites

  • 0

Make a simple browser1 and command button and try going to pogo.com there will be tons of scripting errors because that control wont load javascript

Link to comment
Share on other sites

  • 0

So, I started up VS2010. Created a new VB WinForm project. Dropped a WebBrowser control onto the form. Added the following line of code into the FormLoad event

WebBrowser1.Navigate("pogo.com")[/CODE]

Started it up and within moments I was playing Zuma.

Looks fine to me, and that is literally all I did.

I also changed the URL to:

[CODE]WebBrowser1.Navigate("http://info.uwe.ac.uk/online/blackboard/technical/test.asp")[/CODE]

(first working result from a Google search for 'test if javascript is enabled')

Which shows that, for me anyway, Javascript is enabled.

So your initial premise is wrong. Now we need to figure out where your problem lies, for that we will need lots of info, and maybe a sample project.

Link to comment
Share on other sites

  • 0

Make a simple browser1 and command button and try going to pogo.com there will be tons of scripting errors because that control wont load javascript

STOP ASSUMING THINGS!

As said above, not yelling, just trying to get you to understand a point!

Link to comment
Share on other sites

  • 0

Make a simple browser1 and command button and try going to pogo.com there will be tons of scripting errors because that control wont load javascript

Yes it does, so it must be something with your IE settings (which the browser control is using). The problem is on your side, with the limited information you are giving it will be hard to help you.

Link to comment
Share on other sites

  • 0

Maybe I am an idiot (too), but I have a similar problem.

I created a simple program (to test).

A standard Form with a WebBrowser and a Button on it.

It does nothing more than open a page in the WebBrowser with a Internet based Radio player.

If I open the page in my IExplorer, it works fine (it plays music), but if I run the program from Visual Studio... No player, no music..

Al the items on the page load fine, but not the music player.

 

Any ideas guys?

 

Some more info:

Computer is 64bit Windows 8.1 (also tried it on a Win7 64bit)

Debugger is Visual Studio 13 Ultimate (which I have switched from 'AnyPc' to 'x86') 

 

And the code for the button is:

 

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

WebBrowser1.ScriptErrorsSuppressed = True

WebBrowser1.Navigate("http://www.radioviainternet.be/q-music.php")

End Sub

Link to comment
Share on other sites

  • 0

Here's an idea to check and see if it's IE or VB.

 

 

Add the website to the Trusted Zone, set the zone to Low and see if it works.

 

and for S&G Make sure your Java is up to date (yes I know JS and Java are different)

 

If that doesn't work try resetting IE to defaults.

Link to comment
Share on other sites

  • 0

SOLUTION

 

I actually ran into this the first time yesterday - the Webbrower control works properly. Here's the issue:

For some reason, VB runs the control in IE7 compatibility mode. See here:

http://stackoverflow.com/questions/18668557/javascript-error-when-using-webbrowser-control-and-https-yet-it-works-in-ie

 

It all has to do with Permissions Microsoft added in IE7. Yes, you can view standard webpages and such, but as soon as it tries to run JS or anything else it tends to hit a wall because of the Permissions Microsoft added.

 

This was actually a big problem back when IE7 came out - addins for IE wouldn't work anymore, some programs that relied on IE for certain things didn't work anymore either, and the solution is the same as the one I am posting, although it was done by hand in the registry by the user for whatever app they had installed.

 

I followed a page about the issue to some code which fixes the issue here:

http://stackoverflow.com/questions/18333459/c-sharp-webbrowser-ajax-call/18333982#18333982

 

The code is in C#, but I converted it for VB.net (and have posted it at the end of this explanation).

Once I implemented this code and checked real quick, everything was fixed.

 

Just a FYI.

 

The code adds your EXE to the compatibility database and forces allowing JS and everything else.

#Region "IE Fix"
    Private Shared Sub SetBrowserFeatureControlKey(feature As String, appName As String, value As UInteger)
        If Environment.Is64BitOperatingSystem Then

            Using key = Registry.LocalMachine.CreateSubKey([String].Concat("Software\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\", feature), RegistryKeyPermissionCheck.ReadWriteSubTree)
                key.SetValue(appName, DirectCast(value, UInt32), RegistryValueKind.DWord)

            End Using
        End If


        Using key = Registry.CurrentUser.CreateSubKey([String].Concat("Software\Microsoft\Internet Explorer\Main\FeatureControl\", feature), RegistryKeyPermissionCheck.ReadWriteSubTree)
            key.SetValue(appName, DirectCast(value, UInt32), RegistryValueKind.DWord)
        End Using
    End Sub

    Private Sub SetBrowserFeatureControl()
        ' http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx

        ' FeatureControl settings are per-process
        Dim fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName)

        ' make the control is not running inside Visual Studio Designer
        If [String].Compare(fileName, "devenv.exe", True) = 0 OrElse [String].Compare(fileName, "XDesProc.exe", True) = 0 Then
            Return
        End If

        SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, GetBrowserEmulationMode())
        ' Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
        SetBrowserFeatureControlKey("FEATURE_AJAX_CONNECTIONEVENTS", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_MANAGE_SCRIPT_CIRCULAR_REFS", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_DOMSTORAGE ", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_GPU_RENDERING ", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI  ", fileName, 0)
        SetBrowserFeatureControlKey("FEATURE_DISABLE_LEGACY_COMPRESSION", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_LOCALMACHINE_LOCKDOWN", fileName, 0)
        SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_OBJECT", fileName, 0)
        SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_SCRIPT", fileName, 0)
        SetBrowserFeatureControlKey("FEATURE_DISABLE_NAVIGATION_SOUNDS", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_SCRIPTURL_MITIGATION", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_SPELLCHECKING", fileName, 0)
        SetBrowserFeatureControlKey("FEATURE_STATUS_BAR_THROTTLING", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_TABBED_BROWSING", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_VALIDATE_NAVIGATE_URL", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_WEBOC_DOCUMENT_ZOOM", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_WEBOC_POPUPMANAGEMENT", fileName, 0)
        SetBrowserFeatureControlKey("FEATURE_WEBOC_MOVESIZECHILD", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_ADDON_MANAGEMENT", fileName, 0)
        SetBrowserFeatureControlKey("FEATURE_WEBSOCKET", fileName, 1)
        SetBrowserFeatureControlKey("FEATURE_WINDOW_RESTRICTIONS ", fileName, 0)
        SetBrowserFeatureControlKey("FEATURE_XMLHTTP", fileName, 1)
    End Sub

    Private Function GetBrowserEmulationMode() As UInt32
        Dim browserVersion As Integer = 7
        Using ieKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Internet Explorer", RegistryKeyPermissionCheck.ReadSubTree, System.Security.AccessControl.RegistryRights.QueryValues)
            Dim version = ieKey.GetValue("svcVersion")
            If Nothing = version Then
                version = ieKey.GetValue("Version")
                If Nothing = version Then
                    Throw New ApplicationException("Microsoft Internet Explorer is required!")
                End If
            End If
            Integer.TryParse(version.ToString().Split("."c)(0), browserVersion)
        End Using

        Dim mode As UInt32 = 10000
        ' Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10.
        Select Case browserVersion
            Case 7
                mode = 7000
                ' Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.
                Exit Select
            Case 8
                mode = 8000
                ' Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8
                Exit Select
            Case 9
                mode = 9000
                ' Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
                Exit Select
            Case 10
                mode = 10000
                ' Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
                Exit Select
            Case 11
                mode = 11001
                ' Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
                Exit Select
            Case Else
                ' use IE10 mode by default
                Exit Select
        End Select

        Return mode
    End Function
#End Region

In the Form's New() method, you need to add:

 

SetBrowserFeatureControl()

 

under the InitializeComponent() statement, or it won't work.

 

I hope this helps people.

Link to comment
Share on other sites

  • 0

Finally figured this out. After searching and reading articles for weeks, finally got a vb.net webbrowswer1 object to open a java web page on a windows form!

 

Create a windows form

Add a webbrower object

 

Add this to the code behind the form.  Now your URL with the java should open up just fine!

 

Public Class Form1
    Sub New()
        ' This call is required by the designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
        WebBrowser1.ObjectForScripting = True
        WebBrowser1.ScriptErrorsSuppressed = True
    End Sub
 
End Class
 
-LabTechDrew
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.