You know how a "webapp" can be installed via Mobile Safari by tapping the + button?
And by launching this app via the homescreen your webapp knows that it was launched from the homescreen because window.navigator.standalone
is set to 1...
Well..
I made an iOS app with a UIWebView
that loads a web app. And now I'd like to add the window.navigat开发者_如何转开发or.standalone
property to the dom of my webapp... is that possible?
Thanks
Inject some Javascript into the webview from the objective C to set the parameter manually
[webView stringByEvaluatingJavaScriptFromString:@"window.navigator.standalone=1"];
-Dx
It's not possible. navigator.standalone
is read-only like most native navigator properties. I just checked with an iPhone Emulator in Inspector.
Inject the following into your webview
let script= "Object.defineProperty(navigator, 'standalone', {get:function(){return true;}});"
evaluateJavaScript(script, completionHandler: nil)
That way you can even override read only objects
精彩评论