The URL I need the mobile site redirected to: Deeplink (wake up mobile app). The following code is unable to do the redirect, while manual touch on the button can redirect.
window.location.replace(url);
Next I've tried to trigger the click event programmatically. No idea why is it not working. Refer to all the answer in this question - How can I programmatically invoke an onclick() event from a anchor tag while keeping the ‘this’ reference in the onclick function?
The following is my code.
document.getElementById('BtnClick').href=url;
(function() {
var app = {
launchApp: function() {
window.location.replace(url);
this.timer = setTimeout(this.openWebApp, 300);
var elem = document.getElementById("BtnClick");
if (typeof elem.onclick == "function") {
elem.onclick.apply(elem);
}
},
openWebApp: function() {
console.log("InOpenWebApp");
if(mobileUtil.isIOS){
window.location.replace(iosurl);
}else if(mobileUtil.isAndroid){
window.location.replace(androidurl);
}
}
};
app.launchApp();
})();
What's the possible reason or syntax error?