Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zjhiphop
Last active September 21, 2016 11:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zjhiphop/b51668ffb7c316a11246 to your computer and use it in GitHub Desktop.
Save zjhiphop/b51668ffb7c316a11246 to your computer and use it in GitHub Desktop.
Custom protocol

Specs: https://html.spec.whatwg.org/#dom-navigator-registerprotocolhandler

Examples: https://developer.mozilla.org/zh-CN/docs/Web-based_protocol_handlers

Some answers: http://stackoverflow.com/questions/364895/register-an-application-to-a-url-protocol-all-browsers-via-installer http://stackoverflow.com/questions/7684663/external-protocol-handlers-and-modern-browsers

Mac OS http://stackoverflow.com/questions/595481/register-a-protocol-on-mac-osx

Windows http://msdn.microsoft.com/en-us/library/aa767914%28v=vs.85%29.aspx

Mozilla http://kb.mozillazine.org/Register_protocol

Mobile http://www.mobilexweb.com/blog/click-to-call-links-mobile-browsers

//Make Google Calendar the default application for webcal:// links
javascript:navigator.registerProtocolHandler("webcal","https://www.google.com/calendar/render?cid=%s","Google Calendar")
//Make Gmail the default email application for mailto:// links
javascript:navigator.registerProtocolHandler("mailto","https://mail.google.com/mail/?extsrc=mailto&url=%s","Gmail")

Research Itunes implements:

itmss://itunes.apple.com/us/app/ibooks/id364709193?mt=8 //会自动打开itunes

its.detect.openItunes('https://itunes.apple.com/us/app/ibooks/id364709193?mt=8')

its.detect.openItunes
function (t){t||(t=window.location.href);
var n=its.detect.currentPageIsMacAppStore()||its.url.queryParamValue("mt",t)=="12"||t.indexOf("associateVPPUserWithITSAccount")!==-1||t.indexOf("vpp-associate")!==-1,r=its.detect.currentPageIsMacBookStore(t),i=!1,s;
n?(i=its.detect.macAppStoreDetected(),s="macappstore"):r&&its.detect.macBookStoreDetected()?(i=!0,s="itms-books"):(i=its.detect.itunesDetected(),s="itms");
if(i){t=t.replace(/^http/,s);
var o=t.indexOf("#");
o>-1&&(t=t.substring(0,o));
if(t.indexOf("payPalMIPReturn")===-1&&t.indexOf("firstGateReturn")===-1&&t.indexOf("payclickSignUpReturn")===-1&&t.indexOf("payclickBillingReturn")===-1){var u=t.indexOf("?")===-1?"?":"&";
(new RegExp("itunes[.]apple[.]com/(../station/|WebObjects/MZStore.woa/wa/viewRadioStation[?])")).test(t)&&(t+=u+"cmd=AddStation",u="&"),(new RegExp("itunes[.]apple[.]com/(../radio|WebObjects/MZStore.woa/wa/viewRadioMain)([?/]|$)")).test(t)&&(t+=u+"cmd=ViewStations",u="&");
var a=its.cookies.get("a");
a&&(t+=u+"affC="+its.detect.encodedQueryParameter(a),u="&");
var f=its.cookies.getUnescaped("itcCt");
f&&(t+=u+"itcCt="+its.detect.encodedQueryParameter(f),u="&");
if(document.referrer){var l=its.detect.encodedQueryParameter(document.referrer);
t.length+l.length<400&&(dbg("openItunes: Attaching "+document.referrer),t+=u+"ign-msr="+l)}}}else!its.detect.itunesDetected()||t.indexOf("associateVPPUserWithITSAccount")===-1&&t.indexOf("vpp-associate")===-1?t=itms.PageData.itunesDownloadUrl:t=t.replace(/^http/,"itms");
return dbg("openItunes: "+t),window.location.href!=t&&setTimeout(function(){window.location.href=t},1),!1} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment