这对我有用,但不知道好不好,
var iphoneUrl = 'myScheme://{0}?{1}'
function callNativeFunction(functionName) {
var args = Array.prototype.slice.call(arguments, 1);
if (window.andriod) {
andriod[functionName].apply(andriod, args);
}
else {
var params = '';
for (var i = 0, len = args.length; i < len; i++) {
params += 'param' + (i + 1) + '=' + encodeURIComponent(args[i]) + '&';
}
params = params.slice(0, -1);// remove last &
window.location = iphoneUrl.format(functionName, params);
}
}
callNativeFunction('functionName', 'param1');
这是String.Format,
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};