How To Enable Cookie In Webview For Local Js File?
I want to accept cookies in WebView, but get error Uncaught Error: SECURITY_ERR: DOM Exception 18 The problem occures just in local js file. As Android docs say, I must use setAc
Solution 1:
As far as I can read, setting the cookie host to localhost
on Android triggers a security exception. If you try the same with a remote host it will probably work. That, of course does not solve your problem. Something like this: https://stackoverflow.com/a/24897724/368379 could provide a starting point to handle stuff yourself, but not exactly the same as Cookies.
If you go the JavascriptInterface route, you can implement that in Xamarin.Android like so:
publicclassMyJavascriptInterface : Java.Lang.Object
{
[Export("DoStuff")]
[JavascriptInterface]
publicvoidDoStuff(string stuff)
{
// do something here with the string
}
}
varwebView=newWebView(this);
webView.Settings.JavaScriptEnabled = true;
varinterface=newMyJavascriptInterface();
webView.AddJavascriptInterface(interface, "MyJavascriptInterface");
Then you can call it in Javascript like so:
MyJavascriptInterface.DoStuff("My Awesome String");
Post a Comment for "How To Enable Cookie In Webview For Local Js File?"