Even More on Automatic Download Initiation
I should probably be updating you all on the crazy long weekend I had. I saw many Michigan friends, drank a lot, started a company, cooked a new dish. But that must wait. Today I discovered yet another approach to automatically initiating a software download. This time, from Google Earth. This is how they do it:
<script language="JavaScript" type="text/javascript">
var detect = navigator.userAgent.toLowerCase();
var macurl = "http://dl.google.com/earth/GE4/GoogleEarthMac.dmg";
// Safari does not really support iframes.
if (detect.indexOf('firefox') >= 0) {
document.write('<iframe src=\"' + macurl + '\" width="0" height="0" style="display:none"></iframe>');
} else {
// We do not want to use this approach if we can help it, since it can create navigation/history problems
// on some platforms. Do it only if we think the iframe approach will fail.
window.location = macurl;
}
</script>
</body>
Strangely, in the comments, they say Safari doesn’t like iframes; which is odd, because Apple uses iframes for the iTunes download — unless either Google and/or Apple are doing browser detection before writing out the javascript; something else to investigate. In any case, this is a hybrid iframe/location approach. Their comments also suggest setting the location causes history problems so, while it is the simplest, it’s not ideal. Strange that this is so hard. If it wasn’t for the need to gather reliable stats, we could just link to the damn files!
