• 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

    • Since I watch on a lot of devices and use the music service, I enjoy it. Like if I was just on PC then yeah use adblock. But I'm on watching on my phone, iPad, and TV and not always on my WiFi. The price is getting a little nuts at this point though.
    • Happens EVERY TIME a new version of WMP-HC comes out and you download it in the first few days of release. Happens a lot with other program updates that get listed in the software section here as well.
    • Hitman maker's first showcase will reveal its new James Bond game this week by Pulasthi Ariyasinghe IO Interactive is well known for its development of the Hitman series of stealth and assassination games. In a fitting twist, it was revealed back in 2020 that the studio has begun work on a James Bond game, and after years in development, it seems fans are finally getting a look at the project. Announced today, the project now has a title: 007 First Light. The brand-new game will be revealed in an exclusive showcase event. Coming in as the first ever IOI Showcase, it will be held on June 6 at 6pm PDT on the studio's own YouTube channel. "Join us for the first ever IOI SHOWCASE," said the studio in a social media post today. "Set your reminders and don't miss out on the exclusive reveals and information straight from the team!" Aside from 007 First Light information, the showcase will feature new content reveals for Hitman World of Assassination, the IO Interactive-published title MindsEye developed by Build a Rocket Boy, and more. The game is set to follow James Bond in his start as the MI6 special operative that everyone now knows him as. The origin story is said to be inspired by novels of Ian Fleming as well as the movie franchise, but it will be an original narrative by the developer. While we haven't even seen the game in action yet, IO Interactive CEO Hakan Abrak has already said that he hopes the game is successful enough to spawn a trilogy. "I don't want to speak too big about it, but I just hope we'll do a thing that will define James Bond in gaming for years to come," said Abrak last year. "And that is not only one game, but that we create a universe for gamers to own for many years to come that we can grow with that next to the Bond on the movies." While the studio hasn't revealed much more about 007 First Light since its original announcement, it has already been confirmed as coming for the Nintendo Switch 2 console. Other platforms have not been announced just yet, but it should land for PC, Xbox Series X|S, and PlayStation 5 consoles like the studio's other projects.
    • good grief .... first brittney murphy in the first run now him
    • I do not think that Windows 11 will pick up pace as October 2025 draws near. Even though I was a Windows Vista fan back in the day, this really reminds me of the (lack of) transition between Windows XP to Windows Vista. In the end, Microsoft had to backtrack and extend Windows XP support until Windows 7 was adopted.
  • Recent Achievements

    • Week One Done
      Nullun earned a badge
      Week One Done
    • First Post
      sultangris earned a badge
      First Post
    • Reacting Well
      sultangris earned a badge
      Reacting Well
    • First Post
      ClarkB earned a badge
      First Post
    • Week One Done
      Epaminombas earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      160
    2. 2
      ATLien_0
      124
    3. 3
      Xenon
      120
    4. 4
      snowy owl
      109
    5. 5
      +Edouard
      97
  • Tell a friend

    Love Neowin? Tell a friend!