• 0

[VB.net] WebBrowser control does not load javascript


Question

Recommended Posts

  • 0
  On 17/05/2012 at 14:56, togerland said:

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
  • 0
  On 17/05/2012 at 14:56, togerland said:

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.

  • 0

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

This page wil help you:

  Quote

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:

  • 0
  On 17/05/2012 at 18:16, James Rose said:

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...

  • 0
  On 18/05/2012 at 12:41, togerland said:

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#

  • 0
  Quote

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.

  • 0
  On 18/05/2012 at 12:35, togerland said:

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.

  • 0
  On 18/05/2012 at 12:43, XerXis said:

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.

  • 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.

  • 0
  Quote

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!

  • 0
  On 18/05/2012 at 13:42, togerland said:

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.

  • 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

  • 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.

  • 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.

  • 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
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • This is a common misnomer that Intel refuses to correct, E-Cores the E doesn't stand for efficiency in power (although they are more efficient than performance cores) but are actually "space efficient" which means they occupy much less space for same computational power thus allowing more of them in a footprint.
    • If you have top secret documents from the government or your company, you will not use a user cloud service. Pete Hegseth would like a word. I doubt that security fiasco stops at Signal. Stop being so stupid that you think that your useless information on your PC is as important as you think it is. This is just another crude way of saying it shouldn't matter if have nothing to hide. Not everyone wants to become a product, but you do you. If you cared about the content, you would not use these documents and photos on Android and iPhone phones because the telemetry there is 100,000% worse than on Windows 11. I love the telemetry comment. You cannot prove one way or another if it's better or worse on Windows vs. iOS or Android.
    • Minecraft's big graphics overhaul is now available by Taras Buria It is a big day for Minecraft fans. Mojang has released the long-anticipated graphics overhaul and a new content drop. The Chase the Skies update is now available in Minecraft on all supported platforms, while the Vibrant Visuals overhaul is currently available in Minecraft Bedrock Edition only (it is coming to Java Edition later). Mojang planned a visual update for Minecraft eight years ago, but the Super-Duper Graphics project was cancelled due to performance and other issues. Now, Mojang is ready to try again. This time, however, the update has been successfully delivered to gamers. The reworked graphics in Minecraft include directional lighting, volumetric fog, improved shadows, reflections, godrays, and a lot more. Previously, stuff like this required Minecraft RTX or third-party shaders, but now, the game has improved graphics natively. The update is available across many devices, and you do not need a high-end PC to run it. The upgrade is available on the following systems: Android with Adreno 640, Mali-G68, Mali-G77, Xclipse 530, and higher. iPhones and iPads with the A12 or M1 processor and higher. Any PC with DirectX 12 support. PlayStation 4 and PlayStation 5. Xbox One and Xbox Series X|S. You can enable Vibrant Visuals in display settings. Note that while the upgrade is compatible with many devices, performance still takes a hit. However, you can improve your experience by tweaking different parts of the visual overhaul in graphics settings. Another thing worth noting is that splitscreen multiplayer does not currently support Vibrant Visuals, just like worlds and texture packs. As for the Chase the Skies update, it introduces happy ghasts, new music disks, locator bar for players, environmental fog in the overworld, new background music, and all sorts of small gameplay changes, such as the ability to craft a saddle and a leade, horse taming with carrots, and more. You can read more about the latest Minecraft update in a post on the official website.
    • “We know Biden and Hunter and many in that administration profited tremendously from the support of Ukraine. Nobody talks about that.” Every single right wing talking head has been talking about that and Hunter’s laptop since 2022. Republicans could not even make the case that involved Joe through congressional oversight . ”We do not know what his true motives are other than what we see.” Maybe the way he behaves and talks should show you his true motives (not everything is hidden or a conspiracy). He is a lying bigot who cares about money and power.
  • Recent Achievements

    • Reacting Well
      Cole Multipass earned a badge
      Reacting Well
    • Reacting Well
      JLP earned a badge
      Reacting Well
    • Week One Done
      Rhydderch earned a badge
      Week One Done
    • Experienced
      dismuter went up a rank
      Experienced
    • One Month Later
      mevinyavin earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      693
    2. 2
      ATLien_0
      274
    3. 3
      Michael Scrip
      217
    4. 4
      +FloatingFatMan
      189
    5. 5
      Steven P.
      146
  • Tell a friend

    Love Neowin? Tell a friend!