Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET WebBrowser disable javascript

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

like image 768
HagaS Avatar asked Nov 20 '25 06:11

HagaS


1 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
like image 94
Nmmmm Avatar answered Nov 22 '25 04:11

Nmmmm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!