TD540
TD540

Reputation: 1760

Add window.navigator.standalone to UIWebView DOM

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

Answers (3)

Martin Mlostek
Martin Mlostek

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

hexalys
hexalys

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

Xalior
Xalior

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

Related Questions