2

Windows store App - hi I have webView in my xaml page. This webview show page on some http adress. In loaded page is easy formular for login and I need when user press login button notify in my app. Is there any options?

html part: <input type="submit" value="Login me" id="login">

I find something like this : webView1.Document.GetElementById("").InvokeMember("click"); but its not in RT/W8

pavol.franek
  • 1,396
  • 3
  • 19
  • 42

1 Answers1

3

Here is how you could simulate the click action on your login button:

webView.InvokeScript("eval", new[] { "document.getElementById(\"login\").click();" });

Here is the code if you want to get notified when the button is clicked: Register for LoadComplete and use the folowing code to add a click handler:

private void WebView_OnLoadCompleted(object sender, NavigationEventArgs e)
    {

        webView.InvokeScript("eval", new[]
        {
            "var loginButon=document.getElementById(\"login\");" +
            "if (loginButon.addEventListener) {" +
                "loginButon.addEventListener(\"click\", clickFunction, false);" +
            "} else {" +
                "loginButon.attachEvent('onclick', clickFunction);" +
            "}  " +
            "function clickFunction(){" +
                " window.external.notify('loginClick');"+
             "}"
        });

    }

In the page constructor enable web view notification, you should specify the uri of the page you are working on or you can enable all uri:

webView.AllowedScriptNotifyUris = WebView.AnyScriptNotifyUri;

Finally register for the ScriptNotify event and use the following handler :

private void WebView_OnScriptNotify(object sender, NotifyEventArgs e)
    {
        if (e.Value == "loginClick")
        {
            //Login button have been clicked
        }
    }
Benoit Catherinet
  • 3,335
  • 1
  • 13
  • 12
  • thx for help but I dont need simulate click action but I need when user press this button get notify to application button was pressed - I want show progress bar when user press login button .) – pavol.franek Sep 14 '13 at 15:18