Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I associate a custom MIME-type to my local application in the major browsers?

I want to invent a new mime-type and associate it to a custom application in the browser to enable users to launch my app from a web page. The users of my secure web site are in a closed-environment, meaning this is not a general-purpose, mainstream application - I can configure their browser ahead of time.

Spoon.net does something very similar to enable launching virtualized applications using their mini-kernel plugin.

One of the answers to this question alluded to this method, without details for how to accomplish it.

How do I achieve this in a cross-platform manner on Chrome and IE 8/9? Is there a way to do the mime-type association through browser extensions, either native or through crossrider? How does an app like Adobe Reader or Apple Quicktime achieve this? I want to avoid touching the registry if possible.

What are the risks associated with this method? My site is an intranet web application secured with a certificate and trusted by my users. Any reason I should not go down this path?

EDIT: Apparently this can be achieved in Firefox by manipulating the mimeTypes.rdf file.

EDIT: It looks like JDIC is a Java-based mechanism that could be used for the same thing. Is there a similar non-Java construct? Maybe in Javascript?

like image 555
retrodrone Avatar asked Jun 07 '11 15:06

retrodrone


People also ask

How does browser determine MIME type?

A browser usually identifies a resource's MIME type by observing the Content-Type response header in an HTTP response. Sometimes, developers set values for Content-Type headers that are not appropriate for the response's content.

How do I add a MIME type?

In the Connections pane, go to the site, application, or directory for which you want to add a MIME type. In the Home pane, double-click MIME Types. In the MIME Types pane, click Add... in the Actions pane. In the Add MIME Type dialog box, add the file name extension and MIME type, and then click OK.

Where do I specify MIME type?

Look for a <meta> element in the page source that gives the MIME type, for example <meta http-equiv="Content-Type" content="text/html"> . According to the standards, the <meta> element that specifies the MIME type should be ignored if there's a Content-Type header available.

How do I change the MIME type of a file in Windows?

Windows makes it very convenient to associate programs and file type Right click the file and open up properties. From here, under the general tab, you can choose which app opens this specific file type. Hit change, and navigate to your shim. bat.


2 Answers

I often want to associate a new file type with being a text file. The safest and quickest way of doing this is:

A. Create the file type in Registry if it doesn't already exist

  • Windows -> Search for RegistryEditor -> Open
  • Right-Click HKEY_CLASSES_ROOT -> New -> Key
  • Name the key the same as the extension (e.g. .txttt)
  • Click on the newly created key (e.g. HKEY_CLASSES_ROOT -> .txttt) -> Right-click on (Default) in the right pane -> Modify -> Set to the following values:

(Default) REGSZ txtfile

  • Right-click on the newly created key (e.g. HKEY_CLASSES_ROOT -> .txttt) -> New -> String -> Set to the following values:

ContentType REG_SZ text/plain

  • Right-click on the newly created key (e.g. HKEY_CLASSES_ROOT -> .txttt) -> New -> String -> Set to the following values:

PerceivedType REG_SZ text

B. Associate the file type with a default program

  • Right-click on your file -> Open with -> Choose another app
  • Check "Always use to open with this program"
  • Select the default program

The new file type should open and preview in Windows Explorer with the default text editor program you selected.

like image 175
Chris Sprague Avatar answered Nov 02 '22 07:11

Chris Sprague


It looks like it can be done via a registry change on windows.

[HKEY_CLASSES_ROOT\.atom]
    @="atom_file"

[HKEY_CLASSES_ROOT\atom_file]
    @="Atom Syndication Program"

[HKEY_CLASSES_ROOT\atom_file\shell]

[HKEY_CLASSES_ROOT\atom_file\shell\open]

[HKEY_CLASSES_ROOT\atom_file\shell\open\command]
    @="\"C:\\AtomHandler\\handle.exe\" %1"

[HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/atom+xml]
    "Extension"=".atom"

Further reading on Windows...

And here's how to do so on Linux.

Use xdg-utils from freedesktop.org Portland

like image 36
Jason Avatar answered Nov 02 '22 05:11

Jason