In Javascript, I need to be notified when there's an error loading a URL and override the default behavior. For example, executing the following on iOS Safari...
window.location = 'http://pageDoesNotExist.badFormatting';
... will pop up this alert message...
I would like attach a listener for such an error and do something instead of showing an ugly alert box.
When a user taps a button, I need to launch my app if it is installed, else I need to open the App Store for her to download my app. The accepted solution is:
// Attempt to open app
window.location = 'myApp://';
// If app fails to open, will open app store 0.5 seconds later
window.setTimeout(
function() {
window.location = 'http://itunes.apple.com/myAppId';
},
500
);
The problem here is that the first window.location
opens the ugly alert box when the app is not installed. The code will then fallback to the App Store. When the user returns from the App Store back to Safari, the ugly alert box is still there. As far as I know window.onerror
doesn't fire on mobile Safari.
Window location. The replace() method replaces the current document with a new one.
Window Location Href The window.location.href property returns the URL of the current page.
The Location. assign() method causes the window to load and display the document at the URL specified. After the navigation occurs, the user can navigate back to the page that called Location.
Your solution is here.
Basically, you can use cookies to determine wether your application is installed or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With