VB.NET WebBrowser disable javascript

Is there a way to disable javascript webbrowser in vb.net?

+2
source share
4 answers

works for me:

Private Function TrimScript(ByVal htmlDocText As String) As String While htmlDocText.ToLower().IndexOf("<script type=""text/javascript"">") > -1 Dim s_index As Integer = htmlDocText.ToLower().IndexOf("<script type=""text/javascript"">") Dim e_index As Integer = htmlDocText.ToLower().IndexOf("</script>") htmlDocText = htmlDocText.Remove(s_index, e_index - s_index) End While Return htmlDocText End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim webClient As New System.Net.WebClient Dim result As String = webClient.DownloadString(yourUrl) Dim wb As New WebBrowser wb.Navigate("") Do While wb.ReadyState <> WebBrowserReadyState.Complete Application.DoEvents() Loop Dim script As String = TrimScript(result) wb.DocumentText = script End Sub 
+1
source

Short answer: No.

A slightly longer answer: No, the web browser management API does not allow disabling standard browser functions.

0
source

No really ... but if you get a message about this annoying error message saying that the script is working, you can turn off the web browser's "error suppression" property "true"

0
source

What pop-up message do you want to disable? If this is a warning message, try this by explicitly resolving the window or frame object to your specific needs, Ive just accepted the top-level document, but if you need an iframe, you can access it using window.frames (0). for the first frame, etc ... (again part of JavaScript) ... here is some code suggesting that WB is your web browser ...

WB.Document.parentWindow.execScript "window.alert = function () {};", "JScript"

You should run the above code only after the whole page is loaded, I understand that it is very difficult to do (and the full-featured version has not been published yet), however I have been doing this (full proof) for some time, and you can get hints on how to do this if you read some of my previous answers labeled "webbrowser" and "webbrowser-control", but returning to the question, if you want to cancel the .confirm JavaScript message, just replace window.alert with window.confirm (of course, draw your window object with the correct object to reach the document hierarchy you are working with). You can also disable the .print method using the above method and the new IE9.prompt method.

If you want to completely disable JavaScript, you can use the registry to do this, and you must make changes to the registry before the webbrowser control loads into memory, and every time you change it (on and off), you should reload the web browser control and into memory (or just restart the application).

The registry key \HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\ is the name of the key 1400 , and the value to disable it is 3, and to enable it is 0.

Of course, since there are 5 zones under the Zones key, you need to either change it for the active zone, or for all zones. However, you really do not need to do this if you want to make si supress js dialog pop-up messages.

Let me know how you go, and if I can help further.

0
source

All Articles