JavaScript window.location.href 和 click() 方法在移动设备上不起作用 phone
JavaScript window.location.href and click() methods doesn't work on mobile phone
我需要将用户重定向到 phone 号码。在桌面上一切正常,但 window.location.href 和 click() 方法在移动 phone 的浏览器上不起作用。
代码 1
<a href="tel:555-666-7777" id="test">555-666-7777</a>
<script>
var element = document.getElementById('test');
element.click();
</script>
代码 2
<script>
window.location.href="tel:555-666-7777";
</script>
您必须调用另一个选项卡才能使用“电话”操作,请这样尝试:
$(function() {
$('.phone').click(function() {
var PhoneNumber = $(this).text();
PhoneNumber = PhoneNumber.replace('Phone:', '_self');
//PhoneNumber = PhoneNumber.replace('Phone:', ''); or without _self
window.location.href = 'tel://' + PhoneNumber;
// you can use window.open instead like this: window.open('tel:900300400')
});
});
在HTML中:
<span class="phone">Phone: 900 300 400</span>
我需要将用户重定向到 phone 号码。在桌面上一切正常,但 window.location.href 和 click() 方法在移动 phone 的浏览器上不起作用。
代码 1
<a href="tel:555-666-7777" id="test">555-666-7777</a>
<script>
var element = document.getElementById('test');
element.click();
</script>
代码 2
<script>
window.location.href="tel:555-666-7777";
</script>
您必须调用另一个选项卡才能使用“电话”操作,请这样尝试:
$(function() {
$('.phone').click(function() {
var PhoneNumber = $(this).text();
PhoneNumber = PhoneNumber.replace('Phone:', '_self');
//PhoneNumber = PhoneNumber.replace('Phone:', ''); or without _self
window.location.href = 'tel://' + PhoneNumber;
// you can use window.open instead like this: window.open('tel:900300400')
});
});
在HTML中:
<span class="phone">Phone: 900 300 400</span>