Menu

Alerts/Prompts and Authentication

Help
Jamie
2010-08-22
2014-04-25
  • Jamie

    Jamie - 2010-08-22

    This WebKit Library is absolutely fantastic!!! Keep up the good work.

    The only little thing which I did notice that I liked about Gecko but Webkit.NET doesn't have, is the Javascript alert,prompt,confirm dialogs and the authentication system.

    So like when I go to a password protected site, I get authorization required instead of a password and username prompt.

    Is this possible to implement via code in my own project or do I have to modify the actual Wrapper?

    Thanks!

     
  • Peter Nelson

    Peter Nelson - 2010-08-24

    Hi,

    I suspect these would need to be added to the wrapper.  I'll have a look at GeckoFX and see if I can do the same kind of thing here.

     
  • Jamie

    Jamie - 2010-08-25

    Ok thank-you! I too will do some investigating

     
  • Mitch Connors

    Mitch Connors - 2011-06-03

    Is there any news on this?  How do you authenticate using WebKit.NET?  Even if I have to modify the wrapper, that is fine, but I just can't find much on this.

     
  • Marko Matic

    Marko Matic - 2011-10-14

    Apparently, WebKit.NET guise did not implement methods for displaying message boxes…

    To fix this, you would have to rebuild the WebKit.NET project. First, get the WebKit.NET-0.5-src.zip from here, extract it, and open the contained solution in Visual Studio.

    Then in Solution Explorer find WebUIDelegate.cs, and locate these 3 methods:

    runJavaScriptAlertPanelWithMessage
    runJavaScriptConfirmPanelWithMessage
    runJavaScriptTextInputPanelWithPrompt
    

    First one gets called when javascript:alert() gets executed in the browser. So, if you modify runJavaScriptAlertPanelWithMessage to look like this (do not put System.Windows.Forms in usages!):

    public void runJavaScriptAlertPanelWithMessage(WebView sender, string message)
            {
                System.Windows.Forms.MessageBox.Show(message, "Alert", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            }
    

    Browser will show a .NET information MessageBox titled "Alert" which holds the given message.

    To imeplement confirm(), do this:

    public int runJavaScriptConfirmPanelWithMessage(WebView sender, string message)
            {
                return System.Windows.Forms.MessageBox.Show(message, "Confirm", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes ? 1 : 0;
            }
    

    You may want to use OK and Cancel buttons…

    Prompt is a bit difficult since you must design a form that would allow the user to enter a string… but, this is the way to do it.

    Rebuild all, and voila! :D

     
  • isaac

    isaac - 2012-03-13

    thanks this really helped me

     
  • Olographio

    Olographio - 2014-04-25

    Hello, I know it's late but. Here's for the 'runJavaScriptConfirmPanelWithMessage' method:

    1-Add a reference to 'Microsoft.VisualBasic'
    2-Include 'using Microsoft.VisualBasic;'
    3-Add the following as 'runJavaScriptConfirmPanelWithMessage' method body:


    return Interaction.InputBox(message, "Prompt", defaultText, -1, -1);

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.