Try two download links without user interaction in Javascript or HTML5
My problem is as follows:
I serve a webpage to clients that contains two different download links to the same file. I want the client(!) to test both wi开发者_开发百科thout manually clicking both links (I still present them both as a fail safe). Can this be done with javascript or html5?
What you can do is making an HTTP HEAD
request and look at the status code. The status code tells you whether the resource is available, while a HEAD
request does not fetch the resource contents itself.
This can be done with AJAX, depending on your framework.
E.g. with jQuery:
$.ajax({ type: "HEAD",
url: "download_url",
complete: function(xhr) {
if(xhr.status === 200) { /* is available */ }
else { /* not available */ }
}
});
Set location = "some URL"
twice.
Try this:
<img src="providerSrc" onerror="this.src=fallbackSrc" onabort="this.src=fallbackSrc" />
Customized to your needs of course...
精彩评论