How to get Chrome (and firefox) to recognise a protocol

Any tutorials (or useful resources) should go in here.
Post Reply
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

How to get Chrome (and firefox) to recognise a protocol

Post by bowersbros »

Okay, so you remember the times when you accidentally clicked a mailto: link, and started cursing sicne you knew outlook or mail would take 20 minutes to startup, and that you really wanted to just close it after it started up anyway. And that you meant to copy that email address into gmail and send an email via that.

Remember when google (not too long ago) fixed that annoyance, by allowing you to choose gmail to control your mailto: requests internally with abit of HTML 5 Wizardry.

Well, it turns out you can make your own permission sets, and even your own protocols!

There are several personal protocols that have and can be used.
For example, the skype protocol which if used thusly:

skype:bowersbros?call will startup the skype app, and start phoning me (bowersbros)

Well, you can now get it to work within your website too.

For this example, I shall be using a protocol which I call dftba (dont forget to be awesome - with the hope that Hank, and John will recognize it possibly, and embrace it into their website :) )

I will also be using a Mac, so where i say cmd, use control, and if i use opt / alt, either alt or shift for windows / linux :)

I will also be using chrome.

First of all, navigate to the website that you wish to invoke the protocol on (this would normally be done via their website Javascript code, but we'll be using the javascript console built into chrome)

http://dftba.com

Now open the console (Cmd + opt + J)

Now enter this:

[syntax=javascript]navigator.registerProtocolHandler();[/syntax]

This event takes 3 parameters,

1) protocol name
2) Where to go
3) The name to give this protocol

so we will enter thusly:

[syntax=javascript]...("web+dftba","http://dftba.com/%s","DFTBA");[/syntax]

A few things to notice there.

Firstly, since you're making your own protocol effectively, you need to place "web+" infront of your name. this is required for it to work in Chrome, not sure if it works without in FireFox or not.

secondly, notice the %s in the second parameter. This is so that it can send over the data you enter, and parse it.

Thirdly, the third parameter is whatever you want to appear (for example, above it will appear as Use DFTBA, for the button that you need to click to verify.

This data is sent via the GET attribute, so can be processed easily with PHP.

Now. if you press enter, you will get a confirmation button appear at the top of chrome. If you dont see it, you went wrong, or you havent got a recent version of chrome.

Note, that for you to set one of these up for dftba.com you need to be on the dftba.com website!

now that that is working. Make a simple link. in any page (as long as its in the same browser)

For example, i'm going to use jsfiddle.net

[syntax=xhtml]<a href="web+dftba:info">Some link description</a>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​[/syntax]

Now the above wont actually work for DFTBA.com, but that is only because they dont allow external sites. Im hoping that this publish will get their attention and allow us to do this :)

Thanks,

Alex.
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: How to get Chrome (and firefox) to recognise a protocol

Post by jacek »

Interesting !

Not really sure of a use for this though ?
Image
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: How to get Chrome (and firefox) to recognise a protocol

Post by bowersbros »

well, gmail managed to use it so that gmail opens upon clicking mailto: with the compose and the address loaded into it.
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: How to get Chrome (and firefox) to recognise a protocol

Post by jacek »

Oh ! you can override the standard ones ? That could be more useful !
Image
Post Reply