Question How suppress this popup in my webbrowser ?

prologikus

Member
Joined
Nov 9, 2012
Messages
16
Programming Experience
Beginner
How suppress this popup/error in my webbrowser ( visual basic ) ?

dgoKU.png
 
Have you tried setting e.Cancel in NewWindow event ?
 
How about ScriptErrorsSuppressed property?
 
It may look terrible, but my only success until today was using this small module, it works with Javascript alert dialogs:

Friend Module Liberator
    Private WithEvents TimerLiberator As System.Timers.Timer
    Private TextsLiberator As String(), CountLiberator As Integer, IndexLiberator As Integer, WebBrLiberator As WebBrowser
    Friend Sub StartLiberator(ByRef web_browser As WebBrowser, ByVal timeout As Double, ParamArray texts() As String)
        WebBrLiberator = web_browser : CountLiberator = texts.Count : IndexLiberator = 0 : TextsLiberator = texts
        If texts.Count = 0 Then TimerLiberator = Nothing : Exit Sub
        TimerLiberator = New System.Timers.Timer(timeout)
        TimerLiberator.Start()
    End Sub
    Private Sub ExecuteLiberator(sender As Object, e As System.Timers.ElapsedEventArgs) Handles TimerLiberator.Elapsed
        Try
            Dim BooleanIsBusy As Boolean = WebBrLiberator.IsBusy
            TimerLiberator.Stop() : TimerLiberator.Start()
            Exit Sub
        Catch ex As Exception
            SendKeys.SendWait(TextsLiberator(IndexLiberator))
            IndexLiberator += 1
            If IndexLiberator = CountLiberator Then
                TimerLiberator = Nothing : WebBrLiberator = Nothing : CountLiberator = 0 : IndexLiberator = 0 : TextsLiberator = {}
            End If
        End Try
    End Sub
End Module


And then, whenever I do something upon the WebBrowser that I know it will result in a Javascript Window, I shoot it just before, this way:

StartLiberator(MyWebBrowser, 5000, "{ESC}")


So, after 5 seconds, it will test if WebBrowser is in a thread-frozen state (then trying to get WebBrLiberator.IsBusy raises an error) and so an "ESC" or "ENTER" is sent via SendKeys.

Sure it is a kludge, and it might violate almost every rule of good programming, but it may be worth a try, it if you want. And I thank any suggestion that helps me to perfect this tool upon the same principles.
 
If this is only for one particular page template, you could download the HTML, search for the offending tag(s) or script(s), remove them, then pass the filtered HTML back to the browser.

As a more "universal" solution, you could override the onbeforeunload handler via javascript by adding "window.onbeforeunload = function() {}" in a key script (it has to run once per page loaded, and after all the init scripts and style sheets are ran...).

Here's an example that can be run by greasemonkey on firefox, or simply run on the page by adding it to the page as stated above:

VB.NET:
// ==UserScript==
// @namespace     http://javascript.about.com
// @author        Stephen Chapman
// @name          Exit Block Blocker
// @description   Blocks onbeforeunload
// @include       *
// ==/UserScript==

var th = document.getElementsByTagName('body')[0];
var s = document.createElement('script');
s.setAttribute('type','text/javascript');
s.innerHTML = "window.onbeforeunload = function() {}";
th.appendChild(s);
 
Last edited:
Back
Top