2017-05-16 14 views
0

C#コードのHTMLで起こっているJavaScriptイベントを捕捉できますか?HTMLからのUWP WebView C#イベント

次の例を考えてみましょう。私はその中にボタン付きのhtmlを持っていて、私のアプリケーションではWebViewで表示していて、特定のボタンがクリックされたときに実行するコードがあります。

C#コードでボタンのクリックを捕まえるにはどうすればよいですか?

<html> 
    <head> 
     ....... 
    </head> 

    <body> 
     ........ 
     <button id="idOfButton" name="NameOfButton"></button> 
     ........ 
    </body> 
</html> 

答えて

0

どのように私はC#のコードでボタンのクリックをキャッチすることができますか?

C#コードでボタンをクリックすることができません。

WebViewScriptNotifyイベントを追加できるようになります。ページがwindow.external.notifyを呼び出し、文字列パラメータを渡すと、ホストされたHTMLページがWindowsストアアプリケーションのScriptNotifyイベントを発生させる可能性があります。例えば

:背後

<WebView x:Name="WebViewControl" ScriptNotify="WebViewControl_ScriptNotify" Source="ms-appx-web:///scriptNotify_example.html"/> 

コード:

void WebViewControl_ScriptNotify(object sender, NotifyEventArgs e) 
{ 
    // Be sure to verify the source of the message when performing actions with the data. 
    // As webview can be navigated, you need to check that the message is coming from a page/code 
    // that you trust. 
    Debug.WriteLine(e.Value); 
} 

scriptNotify_example.htmlコード:

<!DOCTYPE html> 
<html> 
<body> 
    <p>This is a simple test page for window.external.notify().</p> 
    <input id="payload" type="text" value="Payload string" /> 
    <button onclick="window.external.notify(payload.value)">Call window.external.notify</button> 
    <p /> 
</body> 
</html> 
+0

これは私がHTMLで行う必要がある変更右? –

+0

私はアプリを書くために勝利jsを使用すると助けになるのだろうか? –

+0

@AravindBelagaje私たちはhtmlを変更できるはずです。 WinJSでも使用できます。 –

関連する問題