0

My web application needs to get some data from the server and also open an external application via its protocol handler. Unfortunately it doesn't work anymore in recent versions of Firefox. It seems that as soon as the document location is changed, Firefox cancels the http request as if the user was leaving the page.

The following much simplified code prints "200" in Chrome and Edge but "0" in (recent) versions of Firefox. How is this supposed to be done?

var xhr = new XMLHttpRequest();
xhr.open('GET', '.');
xhr.onreadystatechange = function() {
  if(xhr.readyState == 4) {
    console.log(xhr.status);
  }
};
xhr.send();
document.location.href = 'myscheme://x.y'
ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
user2543253
  • 2,143
  • 19
  • 20
  • may be just try to wrap that code in `setTimeout` i mean `setTimeout(function(){ document.location.href = 'myscheme://x.y'; },100);` – Inus Saha Jun 25 '18 at 16:30
  • set document.location.href into an iframe instead? – epascarello Jun 25 '18 at 16:32
  • @Inus The example code is much simplified. There's more than one XHR in the actual code in reaction to some other async stuff. A simple `setTimeout` doesn't help. – user2543253 Jun 25 '18 at 16:33
  • @epascarello I had thought about this but couldn't get the browser to open the external application in an iframe. The browser tried to download from the non-existing url instead. Maybe I got the code for the iframe wrong. Is there some other way than setting its "src"? – user2543253 Jun 25 '18 at 16:37

0 Answers0