SKLn-Rad / Xam.Plugin.Webview

Xamarin Plugin for a HybridWebView in PCL projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

window.open() is not working

Karthikeyan-tv opened this issue · comments

Hi @SKLn-Rad ,

The window.open(URL) is not working in this Xam.Plugin.Webview. Do you have any idea to make this work?

Android
Method SetupControl()
add line
webView.Settings.JavaScriptCanOpenWindowsAutomatically = true;

iOS
You can set WKPreferences

 var pref = new WKPreferences();
 pref.JavaScriptEnabled = true;
 pref.JavaScriptCanOpenWindowsAutomatically = true;

 configuration = new WKWebViewConfiguration { UserContentController = contentController, Preferences = pref };

then add method to iOS renderer

[Export("webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:")]
        public virtual WKWebView CreateWebView(
            WKWebView webView,
            WKWebViewConfiguration cfg,
            WKNavigationAction navigationAction,
            WKWindowFeatures windowFeatures)
        {
           // First option - but this is not suitable for me
            UIApplication.SharedApplication.OpenUrl(navigationAction.Request.Url);
            return null;
            // end first option

           // Second option - but it cause some other problem to me
            var request = new NSMutableUrlRequest(navigationAction.Request.Url);
            Control.LoadRequest(request);            
            return null;
            // end Second option
        }

some hint on page

Do somebody have better solution?