gree / unity-webview

zlib License
2.3k stars 694 forks source link

How can I get the click event ? #524

Open DevUNakamura opened 4 years ago

DevUNakamura commented 4 years ago

I would like to hook click event from Unity project. I wrote following source code but I could not get.

void Start()
{
    var go = new GameObject( "WebViewObject" );
    webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
    webViewObject.Init
    (
        cb      : msg => Debug.LogFormat( "HTML からメッセージを取得しました", msg ),
        err     : msg => Debug.LogFormat( "エラーが発生しました", msg ),
        started : msg => Debug.LogFormat( "ページの読み込みを開始しました", msg ),
        ld      : msg => Debug.LogFormat( "ページの読み込みが完了しました", msg ),
        enableWKWebView : true
    );
    webViewObject.LoadURL(url);
    webViewObject.SetMargins(50, 300, 50, 50);
    webViewObject.SetVisibility(true); 

}

Please let me know how to hook click event. Do I need to use Javascript on webpage for getting click event?

Best Regards.

KojiNakamaru commented 4 years ago

The sample app contains a html file in which two onclick events are defined:

https://github.com/gree/unity-webview/blob/5fcf62fe1365e5097036a8d41c3eea8c426cd592/sample/Assets/StreamingAssets/sample.html#L31

https://github.com/gree/unity-webview/blob/5fcf62fe1365e5097036a8d41c3eea8c426cd592/sample/Assets/StreamingAssets/sample.html#L34

If you want to check any click event, you need to inject some javascript as in the comment below:

https://github.com/gree/unity-webview/issues/349#issuecomment-416828427

DevUNakamura commented 4 years ago

Thank you for quick responding. I could solve my problem with your advice.

I appreciate with your support!! Thanks!!