views:

126

answers:

2

Hello Folks,

I have a two part question. The first I think I have an okay answer to....

I am looking to force an external program to be called up to view a configuration file for an application my company is working on. The basic gist I guess is to set the Content-type header to type that your application is associating with, and then serving the contents of the file. I was thinking its simply structured like this:

<?php
Header( "Content-type: application/blahtype" );
?>
output of xml configuration file goes here...

Any other best practices here? Obviously the user is going to have to allow the external application access to this file universally in all browsers, unless they have a plugin installed in their browser that will handle the content-type, like adobe pdf. This isn't viable for our company right now, so we're willing to live with the confirmation screen.

The second part of the question is a little bit more complex, I think. How do we detect if the user has the application installed, and if they do not, serve them different content (a sign up page, or the application executable itself)? I'm not wondering about the logistics of serving different content, but simply the detection process. Is it possible for an application to install a lifetime cookie in the browsers cache installed on the machine? That's not a perfect solution, because the user could clear their cache of course. How else can we accomplish this?

Examples of programs that do this are Amazon MP3 Downloader (I've actually gotten into a bad state with this once or twice), and iTunes U. You can see iTunes U example on Stanfords CS193P page here: http://www.stanford.edu/class/cs193p/cgi-bin/index.php

Much appreciate any advice, Josh

A: 

It may be a good idea to look into using browser extensions for things like this.

jW
+2  A: 

For part 1 of your question, as long as your application is correctly registered to handle that MIME type, then, yes, the browser should prompt the user and launch your application.

An alternative approach would be a protocol handler. Instead of registering a MIME type for your application, you register a “protocol” that goes in a URL, in place of the http://. If your protocol is called myapp, then you could create links like this:

<a href="myapp:data-goes-here-urlencoded">Link</a>

While you can only pass a small amount of information this way, you could pass a GUID or tag that the application, once launched, can use to retrieve the full document from your server.

Edit: For part 2 of your question, iTunes uses a plug-in. Looking at the code that’s used to redirect to iTunes, you’ll see something like this:

<Object id="iTunesDetector" height="1" classID="CLSID:D719897A-B07A-4C0C-AEA9-9B663A28DFCB" width="1"></Object>

It’s followed by some JavaScript to detect whether that plug-in was loaded. If it was, then iTunes must be installed and it launches iTunes using the itms: protocol (just like the myapp: protocol in the example above).

The problem here is, you would have to write a browser plug-in.

Nate
Thanks for the answer! I think either application launching solution seems to be a good one. Now the question is how do I cover all my bases with freaking plugins for every browser known to man... might just have a cookie fallback when I serve somebody the download file until we can get all those bases covered.
Josh