gree / unity-webview

zlib License
2.25k stars 687 forks source link

Confirm Navigation Android Popup #282

Open scottywaz opened 6 years ago

scottywaz commented 6 years ago

Android version of our app is getting this popup when trying to navigate to a URL. screen shot 2018-02-12 at 4 21 54 pm

I attempted to do this in the sample and it works fine. We do have other plugins in our codebase and I'm wondering if anyone knows of an Android Manifest setting that I missed or might be causing this.

In my googling around this is the only related thing I could find: stackoverflow So do I need to add Native code and add this line?

KojiNakamaru commented 6 years ago

The page should define window.onbeforeunload as in the stackoverflow page you described. If you want to remove it, you can utilize EvaluateJS() as below (please adjust the timeout delay adequately):

--- a/sample/Assets/Scripts/SampleWebView.cs
+++ b/sample/Assets/Scripts/SampleWebView.cs
@@ -46,6 +46,7 @@ public class SampleWebView : MonoBehaviour
             ld: (msg) =>
             {
                 Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
+                webViewObject.EvaluateJS(@"setTimeout(function() { window.onbeforeunload = null; }, 1000);'");
 #if !UNITY_ANDROID
                 // NOTE: depending on the situation, you might prefer
                 // the 'iframe' approach.
scottywaz commented 6 years ago

Any ideas why this would be Android only and not seen on iOS?

KojiNakamaru commented 6 years ago

That is because beforeunload isn't supported on iOS: https://caniuse.com/#search=beforeunload