Is there any way to check if a URL scheme is currently registered on the phone... with javascript?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- CALayer - backgroundColor flipped?
This is based on the answer of mrahman. As noted, by JoshNaro new Date() gives back a wrong date when called inside the timeout. Tests suggest that the date is not updated in threads that are started before the app is deactivated.
A further ugly setTimeout called after activation will create a new thread with the current date.
This was tested on iOS 8.
I try to use just the 'pagehide' event, but then it not work into Firefox. I created this version here http://jsfiddle.net/thiagomata/6tvoc4f1/2/ what works in Firefox, Google Chrome and Safari. I have not tested in Internet Explorer yet.
One thing what was necessary to make it work into Firefox, was use Iframe to set the src. This allows me to call the app without leaving my page.
I found
pagehide
event to be more robust than depending on system time. For those of us who prefers a non-jQuery favor, here is the snippet.No, not from a webpage.
Another great (at least working in latest browser versions) workaround is to check if the browser window has focus after a short timeout, this way you can show a dialog box to the user only if the URI scheme didn't work
HTML:
Javascript (using jQuery here):
Here is a working jsFiddle, just update it with your own URI scheme: http://jsfiddle.net/mF6TZ/
Not seamlessly. But there is a way similar to checking if a pop-up was blocked or not.
When you try a URL scheme which is not supported, Safari will warn the user that it doesn't know what to do with it and stay on the same page.
So if you gave your app-call some time to activate, say 300 ms, and then do something else to respond to the non-existence of the scheme.
It's not the prettiest but it works: