Access localStorage in iOS apps
I'm serving up remote html/javascript content into an iPad app. Javascript code runs great and html renders fine, but any attempt to access localStorage throws "Security_err: dom exception 18".
I was attempting to use localStorage because Safari by default won't accept third party cookies. Is there any way to set cookies or store values in localStorage from开发者_开发百科 remote content to maintain state when served into an iOS app?
I know this question is old (and gaining dust), but here's an answer.
exception 18 is usually a cross domain permission issue.
consider one of the following solutions:
Instead of preloading the html string and then using
[myWebView loadHTMLString:str baseURL:url];
, just let the webview handle the whole request life cycle using[myWebView loadRequest:someNSURLRequest];
If your'e using Cordova, Edit your Cordova.plist file, add a new entry to the ExternalHosts list with the value * (please consider the security compromise with this solution).
精彩评论