[英]Redirect from website to mobile phone app
Someone asked me to create a script that redirect a mobile user directly to the phone app with a phonenumber inserted.有人让我创建一个脚本,将移动用户直接重定向到插入电话号码的电话应用程序。 Instead of viewing the webpage.而不是查看网页。
Somehow my script only works on a on-click event and not on the page load event.不知何故,我的脚本仅适用于点击事件,而不适用于页面加载事件。
I tried to open the phone app with window.open('tel:+612345678') and window.location.href = 'tel:+612345678';我试图用 window.open('tel:+612345678') 和 window.location.href = 'tel:+612345678'; 打开手机应用程序。 But without succes my latest attempt is to create a link element dynamically and then call window.location.href=document.getElementById('redirectToPhoneElement').href;但没有成功,我最近的尝试是动态创建一个链接元素,然后调用 window.location.href=document.getElementById('redirectToPhoneElement').href; but also without succes.但也没有成功。
(function(){
var tel = "tel:+612345678"; // hier telefoonnummer invullen zonder +
function detectmob() {
if(navigator.userAgent.match(/Android/i)){
var dRatio = window.devicePixelRatio;
var width = screen.width * dRatio;
var height = screen.height * dRatio;
if(window.innerWidth > window.innerHeight){
// check landscape max width
if(height / dRatio <= 480){
//document.writeln('ls mobile');
GoToPhone();
}
} else {
if(width / dRatio <= 480){
//document.writeln('p mobile');
GoToPhone();
}
// check potrait width
}
} else if(navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i))
{
GoToPhone();
}
}
function GoToPhone(){
var telLink = document.createElement("a");
var telText = document.createTextNode("call");
telLink.appendChild(telText);
telLink.href=tel;
telLink.id="redirectToPhoneElement";
document.body.append(telLink);
window.location.href=document.getElementById('redirectToPhoneElement').href;
}
detectmob();
})();
How can I make the redirect work automatically?如何使重定向自动工作?
Greets问候
You can call function on window loaded with href="tel: 3281769362"
, it also works on mobile phone您可以在加载了href="tel: 3281769362"
窗口上调用函数,它也适用于手机
function call() { document.getElementById("call").click(); } window.onload = call;
<a id="call" href="tel:123-456-7890">Wait</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.