Android Webview and history.pushState? - javascript

The Android Webview allows an Android application to handle a user clicking on a link by opening the destination within the webview, instead of opening it in an external browser.
It is then possible to maintain a history of these page loads so that a user can go forward and backward within the webview, much like a "real" browser:
http://developer.android.com/guide/webapps/webview.html#NavigatingHistory
My questions are:
Can the Android webview history management "natively" handle a webpage pushing to the history stack using something like window.history.pushState?
If so, what data structures/API are used to manage the history? How does the webview differentiate between two versions of the page that have the same URL but different DOM states?
If not, can such support be implemented by an application developer?
Which HTML5 APIs (if any) does the Webview support?

Related

JavaScript - one link, all app stores, non-Safari detected

I'd like to have a single 'Get App' link that auto-detects the user's device type and browser and directs to the appropriate location (iTunes, Google Play, or website sign-up). I am currently using Onelink.to, but it has the following limitations:
if you're on iOS using a non-Safari browser (like Chrome) you end up looking at a bunch of raw JSON because it doesn't know to launch the App Store app. In this case, I'd prefer to direct to the iTunes website or better yet, deep link into the App Store app.
if using the link on your own site and a user is on a device that redirects to a different page of your own website, it complicates setting up event-based goals in Google Analytics
Are there any good JavaScript solutions that handle the App Store redirect while excluding this action on browsers that don't support the iTunes headers?
Thanks!
You can use javascript navigator.userAgent and parse it to detect the device. Then just generate the link according to it.
Here is an example for ios detection:
Detect if device is iOS

Open non-whitelisted URLs in Cordova in ChildBrowser rather than main Webview

I'm trying to implement the official Twitter and Facebook share buttons in my Cordova/Phonegap app, and I'm running into major difficulties with them. Both of them attempt to load an iframe element to display their buttons, which works, but clicking either of them causes them to open in the Webview, with no way to open them instead in the ChildBrowser. This becomes an issue when the user is done sharing but can't go back to the app due to a lack of navigation buttons.
Is there some way to open a list of URLs in ChildBrowser by default instead of Webview?
Well you can use the:
ChildBrowser.showWebPage();
command to open non-white listed URL's.
Coming in 2.3.0 we will overload window.open() in so that you can specify whether or not you want the url opened in the main web view, the OS browser or the special in app browser that does not have access to the Cordova API.

Can I create HTML 5/JS application that calls windows phone 7 silverlight app

I want to build 1 UI for several phones (windows phone, Android, IPhone, etc).
My plan is to create an HTML5 UI, and use JS to invoke applications that are installed on the mobile device.
For example, I create windows phone 7 application without UI, and invoke functions of this application from the JS in the HTML 5 UI.
Same goes for android, IPhone, etc.
Is this plan feasible at all?
- How can I call windows phone 7 silverlight app/Android from JS?
Calling a native app from the browser is
possible on iOS: Opening Native App. from Safari
possible on Android: Launch custom android application from android browser
impossible on Windows Phone 7
On iOS, you can't create a web app that calls native code, period. You mention that you want the app to have no UI, so I'm assuming you want to have a web app that invokes native code which in turn causes something to happen in the web app, or even causes something to happen on the device. Won't happen. You can use the iPhone's Custom URL Scheme to LAUNCH an application with given parameters so that when it opens it immediately does something, but you will get kicked out of the browser and in to your app. And App Store Guidelines wouldn't let you make an app that has no UI. It also doesn't allow for the creation of apps that are just WebViews wrapped around HTML.
On Android, I would imagine that you could create an app that is nothing more than a WebView that loads your webapp, and in that way you would have access to the native code you wrote for the device, but I don't think that would meet up in the middle the way you want it to when it comes to having the native code manipulate your web app. Plus Android UI's are mostly XML with a little bit of backing code so at that point you may as well be making a native app.
The browser in Windows Phone 7 does not currently support HTML5, though it is expected to arrive later this year. That said, I would extremely surprised if there was ever a public API that enabled a web site to open an application on the host device and I'd be surprised if this was allowed on Android or iPhone, too.
The only application that I'm aware of that exhibits this behavior is the YouTube application. If you visit YouTube.com on the WP7 browser, then it either launches the YouTube app if you have it installed, or prompts yout to download and install it. So, the capability is there, but I doubt very strongly if Microsoft would ever open it up beyond a close partnership for specific applications.
In Windows Phone 7, you can use the WebBrowser control within an application to host/browse web content, and from the application you can call javascript methods exposed by that page as described by Shawn Wildermuth in his Navigating with the WebBrowser Control on WP7 post.

Launch mobile Safari from UIWebView *without* modifying app source?

I'm developing a small site that will only be viewed in-app inside a UIWebView, and one page has several links to an external website. I'd like these to open in mobile Safari, but all links inside the app load within the webview. Modifying the source of the app isn't an option since the site needs to be live before any changes could be submitted.
Is there a way to force a link inside a UIWebView to launch mobile Safari using HTML/5 or Javascript? Mimic shouldStartLoadWithRequest? Sneaky, hacky workarounds or brilliant alternate solutions?
(And, out of sheer curiosity... why not?)
It would be bad design to let sites access the frameworks on the iPhone via simple HTML. This would open up all sorts of security holes. Its not web behavior you want to alter, so I think you may need to change the app source. I still don't understand why that isn't an option. Could you go into more depth?
One option would be to add a custom URL handler. Your website could then determine if the "broswer" is the app and serve custom URLs for those links you'd like to maintain (aka open) in your app. Then, any standard HTTP/s URLs would open in Mobile Safari.
In other words, have your web server provide urls like myappurl:// for the links you'd like your app to handle, and http:// which would open Mobile Safari.

How do I trigger execution of a method within an iPhone application from Javascript?

Is it possible to trigger the execution of a method within an iPhone application from JavaScript on a web page?
For example, I'd like to have a button that opens the iPhone camera application. Is this possible?
The question is worded a bit confusingly, but if you're displaying a UIWebView in an app and want to have Javascript from the webpage interact with the app, this can be done using the webView:shouldStartLoadWithRequest:navigationType: delegate method. See Apple's documentation: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html
If you are trying to open the Camera app from an actual webpage running in Safari, you're out of luck. You can only open apps with associated URLs. (For example, tel: URLs to make phone calls, itms: URLs to launch the iTunes Store or App Store, etc).

Categories