admin管理员组文章数量:1136458
I designed a mobile web page. There I have a phone number field, which on clicking should call that particular number. I can't use:
<a href="tel:+1800229933"></a>
Because I have added the phone number field using table tag as follows:
<table>
<tr>
<td>Phone: 900 300 400</td>
</tr>
</table>
Are there any other methods(like OnClick event) to call that phone number on clicking that column?
I designed a mobile web page. There I have a phone number field, which on clicking should call that particular number. I can't use:
<a href="tel:+1800229933"></a>
Because I have added the phone number field using table tag as follows:
<table>
<tr>
<td>Phone: 900 300 400</td>
</tr>
</table>
Are there any other methods(like OnClick event) to call that phone number on clicking that column?
Share Improve this question edited Apr 12, 2020 at 19:46 AmerllicA 32.4k17 gold badges143 silver badges166 bronze badges asked Jul 27, 2013 at 11:26 msgmsg 1,5403 gold badges19 silver badges28 bronze badges 1 |7 Answers
Reset to default 118You can simply add an onclick
handler to your <tr>
tag, then call window.open("tel:+1800229933");
.
Like so:
<table>
<tr onclick="window.open('tel:900300400');">
<td>Phone: 900 300 400</td>
</tr>
</table>
Change this:
<table>
<tr>
<td>Phone: 900 300 400</td>
</tr>
</table>
to:
<table>
<tr>
<td>
<a href="tel:+900300400">Phone: 900 300 400</a>
</td>
</tr>
</table>
Find the cell content with jQuery, replace the "Phone:" part and make it a link. The selection of the cell with a class is one way of doing it. Another would be to select in the real table the cell with a code similar to "the second cell in each row of the table". Here a working example:
<html>
<head>
<title>Test</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function() {
$('.phonecell').click(function() {
var PhoneNumber = $(this).text();
PhoneNumber = PhoneNumber.replace('Phone:', '');
window.location.href = 'tel://' + PhoneNumber;
});
});
</script>
</head>
<body>
<table>
<tr>
<td class="phonecall">Phone: 900 300 400</td>
</tr>
</table>
</body>
</html>
The certain answer for the title of the question, hence, without using <a>
tag is to make a helper function to simulate the action of <a href="tel:
:
const simulateCall = phoneNumber => window.open(`tel:${phoneNumber}`, '_self');
The target _self
causes we have an exact look like call simulation just like clicking <a href="tel:
.
Now the simulateCall
helper function can be used anywhere. like my case:
const callHandler = phoneNumber => () => {
// I want to do something here then make a call
simulateCall(phoneNumber);
};
~~~
<SomeComponent onClick={callHandler} ...
Shorted answer
this will keep you in the same window
window.location = "tel:495898694"
while this will open another tab and then call the number
window.open('tel:900300400');
Try this may be you'll find it helpful https://www.theharnishes.com/phone.html
If you need to open the dialer of mobile phone when clicking on a button, you can try this:
onClickBtn={() => window.open(`tel:+919876543210`)}
example:
<ActionButton
onClickBtn={() => window.open(`tel:+919876543210`)}
title="Call Owner"
icon={<LeftCircleTwoTone />}
/>
本文标签: htmlhow to call a phone number through javascript without using ltagt tagStack Overflow
版权声明:本文标题:html - how to call a phone number through javascript without using <a> tag? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736938125a1957018.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
a
tag to the table cell?? – PeeHaa Commented Jul 27, 2013 at 11:27