Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  128] [ 5]  / answers: 1 / hits: 19624  / 11 Years ago, fri, august 23, 2013, 12:00:00

How do I check if a call to window.location failed because the given URL was invalid, etc? Is there some event I can set on the window object or on some other object that can catch this?


More From » dom-events

 Answers
18

Finally got it to work using a workaround that is not a generic solution as I originally hoped:



I am using the fact that the link I am trying to open is a custom url scheme (e.g. myxx://localhost) on mobile, and if it fails, the action I want to perform is a redirection to a standard appstore URL (os-specific). The workaround tries to open the custom URL, and if it fails, the timeout function kicks in shortly after, and opens an alternative url:



setTimeout(function() { window.location=alternateUrl; }, 25);
window.location = customUrl;


The downside is that when the customURL fails, a standard safari browser shows a message box that the site could not be opened, but at least it still redirects the user to the appstore.


[#76179] Thursday, August 22, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
quinlanhenryf

Total Points: 743
Total Questions: 93
Total Answers: 118

Location: Australia
Member since Sat, May 27, 2023
1 Year ago
;