Reputation: 1760
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.navigator.standalone
property to the dom of my webapp... is that possible?
Thanks
Upvotes: 4
Views: 1979
Reputation: 2970
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
Upvotes: 0
Reputation: 5257
It's not possible. navigator.standalone
is read-only like most native navigator properties. I just checked with an iPhone Emulator in Inspector.
Upvotes: 0
Reputation: 141
Inject some Javascript into the webview from the objective C to set the parameter manually
[webView stringByEvaluatingJavaScriptFromString:@"window.navigator.standalone=1"];
-Dx
Upvotes: 1