0

Is there any javascript framework/technique that allows to send asynchronous requests with custom scheme urls? Trying this with Ajax:

$.ajax({url: "myapp://root", success: function(result){
     console.log(result);
}});

expectedly gets me the below error

XMLHttpRequest cannot load myapp://root. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

I'm trying to figure a way to check whether a deep link sent to my iOS app has been successfully received before I redirect to its iTunes page. My current javascript waits for a timeout before redirecting to iTunes, and that's not working as intended; a dialog pops up to ask whether the user wants to open the app, and if the timeout expires before they make their decision, they still get redirected to iTunes even if the dialog hasn't been answered/dismissed yet.

Here's my javascript:

window.location = "myapp://somepath";
setTimeout(function() {
    window.location = "https://itunesurl";
}, 500);

Obviously increasing the timeout is not the solution I'm looking for.

ALTN
  • 659
  • 9
  • 26
  • 2
    Well, if the redirect succeeded, you left the page, so I'd guess the answer is **no**. – adeneo Jan 27 '16 at 19:36
  • @adeneo Just made my question more accurate – ALTN Jan 27 '16 at 19:59
  • 1
    Have you checked this question? http://stackoverflow.com/questions/24779312/simplest-cross-browser-check-if-protocol-handler-is-registered – Viktor Kukurba Jan 27 '16 at 22:19
  • @ViktorKukurba yes I tool a look there. The javascript code I shared in my question was actually from there. In fact the code works perfectly in all browsers and on Facebook, but it kinda partially fails with twitter. Twitter redirects to iTunes even though it does detect the app and prompts to open it. The timeout callback always gets called when twitter is in charge. – ALTN Jan 27 '16 at 23:01

1 Answers1

1

You can try to use AJAX request using jsonp.

Viktor Kukurba
  • 1,360
  • 9
  • 14
  • @Victor Thanks for the suggestion. I did a little research about jsonp but it doesn't seem like I could apply it to my case. I need to pass a url with a custom scheme to iOS on the client side, rather than loading data from a different domain (which seems to be jsonp job) – ALTN Jan 27 '16 at 21:25