There is an application on ios that listens to a specific url scheme, if you open a custom url in the safari browser that listens to the application ( myapp://en/news?id=2 ), the application opens, but if the application does not open, then this error appears safari cannot open the page because the address is invalid

standard ios solution through Universal Links cannot be used as in the support version with ios 6

An example of how a person solved this error, but it did not help me

  • and what is the expected behavior? - Grundy
  • If possible, publish the solution found in response to your question . I am sure it will help many of your colleagues in the future. - Nicolas Chabanovsky
  • Expected behavior, this person follows the link, if the application is installed, then it opens, if the application does not exist, then the web page opens Solution: for iOS 9-10, Universal Links were used and for versions below js crypt I attach the script below, - Dmitry Tyutryumov

1 answer 1

 <script> var protocolToReplace = "http:"; if (window.location.protocol == "https:") protocolToReplace = "https:"; if ("standalone" in window.navigator || window.navigator.appVersion.indexOf("Win")!=-1) // определяем платформу { function tryOpenApp() { var iframe = document.createElement("iframe"); iframe.style.border = "none"; iframe.style.width = "1px"; iframe.style.height = "1px"; iframe.src = "mycustomscheme://projectDomain.com" + window.location.pathname + window.location.search; var url = "mycustomscheme://projectDomain.com" + window.location.pathname + window.location.search; document.body.appendChild(iframe); String.prototype.format = String.prototype.f = function(){ var args = arguments; return this.replace(/\{(\d+)}/g, function(m,n){ return args[n] ? args[n] : m; }); }; var meta = document.createElement('meta'); meta.httpEquiv = "refresh"; var pathname = window.location.pathname.slice(14); url = protocolToReplace + "//www.projectDomain.com" + pathname + window.location.search; meta.content = "1; url={0}".f(url); document.getElementsByTagName('head')[0].appendChild(meta); } } </script> 
  • don't forget to take - Max Mikheyenko