I found the solution, admittedly, not the best, but works for me.
I created a singleton WebViewHandler class that looks like
class WebViewHandler { private static WebViewHandler instance; public bool isWebViewReady { get { return webView != null; } } public WPCordovaClassLib.CordovaView webView; private WebViewHandler() { } public void setWebView(ref WPCordovaClassLib.CordovaView webView) { this.webView = webView; } public static WebViewHandler getInstance() { if(instance == null){ instance = new WebViewHandler(); } return instance; } }
Then I install webview in the constructor on HomePage like this:
public HomePage() { InitializeComponent(); CordovaView.Loaded += CordovaView_Loaded; WebViewHandler.getInstance().setWebView(ref CordovaView); }
After installing WebView, I can call InvokeScript from any other class:
WebViewHandler.getInstance().webView.CordovaBrowser.InvokeScript("MyJavaScriptFunctionThatIWishToCall");
Mike bryant
source share