I found that there was no way to do this without "cheating" in some way. I decided to create a <a>
element in my page and dynamically change its href
attribute, then triggering the click
event on it with Javascript. Here is what I did :
CSS
a#sendToiOS {
display:block;
position: fixed;
bottom: -1px;
right: -1px;
z-index: -1;
opacity: 0;
width: 1px;
height: 1px;
}
Javascript
var sendToiOS = function(protocol, action, params) {
var e = document.createElement('a');
e.id = 'sendToiOS';
var strParams = "";
if(typeof params !== 'undefined') {
Object.keys(params).forEach(function(key) {
strParams += strParams != "" ? '&' : '';
strParams += key+'='+encodeURI(params[key]);
});
}
e.href = strParams.length > 0 ? protocol+'://'+action+'?'+strParams : protocol+'://'+action;
document.getElementsByTagName('body')[0].appendChild(e);
e.click();
e.parentNode.removeChild(e);
}
Calling sendToiOS('mycustomprotocol', 'some_action', {foo: 'bar', foo2: 1337});
would then trigger a call to mycustomprotocol://some_action?foo=bar&foo2=1337
.