问题
I been searching around and cant seem to find anything relating to this. Basically i made a windowless app which uses the gecko webbrowser. Thing is, if i try browse to a site that does not exist. Example: www.gets.commmss, it will show me an alert box saying www.gets.commmss could not be found. Please check the name and try again.
I dont want this to show as i handle these errors myself using the navigated
& NavigationError
handlers. Thing is, i cant seem to disable this annoying alert box! Any ideas much apprecited.
The geckofx version i am using is: GeckoFX v33.0.9.0
I am using visual studio 2012 and it is a windows form application.
Screenshot:
This must be done via the app somewere as i dont think this is a javascript thing?
回答1:
You need to override the PromptService.Alert(). The following code works for GeckoFX 45:
public class NoPromptService : PromptService
{
public override void Alert(string dialogTitle, string text)
{
Debug.WriteLine(text);
}
}
Then run this after initializing GeckoFX:
PromptFactory.PromptServiceCreator = () => new NoPromptService();
I got this from an older answer on the GeckoFX issue tracker.
回答2:
VB.net GeckoFx Disable Alert
Dim MyPath = My.Computer.FileSystem.CurrentDirectory
Public Sub New()
Xpcom.Initialize(MyPath + "\xulrunner")
' This call is required by the designer.
InitializeComponent()
Xpcom.ProfileDirectory = MyPath + "\profile"
Gecko.PromptFactory.PromptServiceCreator = AddressOf PromptServiceCreator
End Sub
Function PromptServiceCreator()
Dim val As New NoPromptService()
Return val
End Function
Public Class NoPromptService
Inherits PromptService
Public Overrides Sub Alert(ByVal dialogTitle As String, ByVal text As String)
Debug.WriteLine(text)
End Sub
End Class
来源:https://stackoverflow.com/questions/48092059/disable-alert-boxes-when-site-not-found-gecko-fx-vb