• 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

    • The Radeon RX 9060 XT is 5% slower than the GeForce RTX 5060 Ti, but the GeForce RTX 5060 Ti is 23% more expensive, at least when comparing MSRPs.
    • I would love to see Musk's face! 🤣🤣🤣
    • I think each AI option has their ups and downs. For Copilot, I find it more personable in how it talks compared to GPT & Gemini. I also appreciate the open ended questions it often provides at the end of its responses to keep the conversation going.
    • Microsoft offers free access to AI video creation with Bing Video Creator by Pradeep Viswanathan Two years ago, Bing Image Creator became one of the first major online services that allowed users to create images from text using OpenAI’s DALL-E model. Today, Microsoft is introducing Bing Video Creator, powered by OpenAI’s Sora, allowing users to create videos with text prompts. Despite announcing Sora last year, OpenAI has not been able to expand its availability to millions of ChatGPT users due to huge AI infrastructure requirements. It is still only available to ChatGPT Pro subscription users, which costs about $200 per month. Recently, Google announced its Veo 3 video generation model, which performs significantly better than OpenAI’s Sora, to all Gemini paid subscribers, making video generation accessible to even Gemini Pro subscribers, which costs just $20 per month. Now, Microsoft is democratizing access to video generation models by making Bing Video Creator free for all Bing users. Bing Video Creator is rolling out today globally (excluding China and Russia) on the Bing Mobile App, and it will be coming soon to the Bing desktop experience within Copilot Search. Bing Video Creator users will have the ability to choose between Fast and Standard generation speeds. Each user will have 10 Fast creations; following that, users can redeem 100 Microsoft Rewards points for each Fast creation or continue with Standard creation speeds. Once you have downloaded the Bing mobile app, here’s how you can access the Video Creator feature: Open Video Creator within the Bing Mobile app by clicking on the menu in the bottom right corner and selecting “Video Creator.” Just type in a text description of the video you want to create in the prompt box. Once the prompt text is ready, just tap “Create.” Or you can also just type directly into the Bing mobile app search bar "Create a video of..." to create a video. You’ll receive a notification when your video is ready to view. If required, you can also download the video or share it via social media or email. You will also have the ability to copy a direct link to the video for easy sharing elsewhere. Microsoft will be storing the generated videos for up to 90 days in your account for easy access later. Microsoft noted that the Bing Video Creator videos are 5 seconds long and can be created only in 9:16 format for now. Microsoft will be adding the 16:9 format soon. When you are waiting for your video to be created, you can also queue up another two videos. Once one of the slots becomes available, you can add another one to the queue. When Bing Video Creator becomes available on desktop, you can visit Bing.com/create for both image and video creation needs.
  • 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
      150
    2. 2
      ATLien_0
      122
    3. 3
      Xenon
      121
    4. 4
      snowy owl
      99
    5. 5
      +Edouard
      95
  • Tell a friend

    Love Neowin? Tell a friend!