That only works well for intents that follow a fire and forget pattern,
where a standard URL would have normally applied.
If you have a use-case for using the href attribute to invoke intents, why
not build a shiv? Something like this:
//---
function handleIntentURI(uri) {
var type = uri.substring(0, uri.indexOf(':')),
args = uri.substring(type.length+1).replace(/^\?/g,'').split('&'),
params = {},
i, j, intent;
for (i=args.length; i--; ) {
j = args[i].indexOf('=');
params[decodeURIComponent(args[i].substring(0, j))] =
decodeURIComponent(args[i].substring(j+1));
}
intent = new Intent("
http://webintents.org/"+type, "application/json",
JSON.stringify(params));
navigator.startActivity(intent);
}
document.addEventListener('click', function(e) {
var t=e.target, h;
do {
if (t.nodeName.toLowerCase()==='a') {
h = t.getAttribute('href');
if (h.substring(0,7)==='intent:') {
handleIntentURI(h.replace(/^intent:\s*/g,''));
e.preventDefault();
return false;
}
break;
}
} while((t=t.parentNode) && t!==document.body)
});
//---
Note the issues with trying to represent intents as links: you don't know
the content-type, or what format to use for the parameters. Perhaps
"content-type" could be added as one of the urlencoded parameters, but it
would cause naming conflicts.
It might be worth investigating how the URI is formed, namely adding a
section for the content-type. If the rest was then based off the format of
a data-URI, there would be enough information to construct a logical intent
from the simple string:
intent:share:text/uri-list,name=XXX&linkback=my-url
Just a thought.
- Jason