The JavaScript below code has two steps.
Step 1: go to .pdf, .doc, .exe or something which not html native. If location.href has took over the browser window then there is no need to do step 2. (PDFs usually take over browser window). Most other things kick off a download manager process. Such as .exe. But there are some things such as word docs that could be either a download or show right in the browser window depending on browser setup. I want it to do what hef.location would make it do.
Step 2: But if it is downloading a file such as an .exe after that process is done then go to home page.
Or solution for just waiting 5 seconds between steps 1 and 2 seem to work most of the time. But on a slower connection it doesn't always works. Then it goes to home page without finishing the first href.location call and they never see the PDF and just see home page.
FYI...The reason I am wrapping them in setTimeOut is related to this firefox issue. Stack Overflow: 864633 assigning-to-document-location-href-without-clobbering-history
My question: Is there a way to tell when the location.href process gets completed?
<script language="JavaScript"><!--
function windowOnLoad() {
setTimeout(function(){
location.href='/someurl/something.pdf'; //sometimes this is .doc file
},0);
setTimeout(function(){
location.href='/homepage';
},5000);
return false;
}
//-->
</script>