简体   繁体   中英

how can i make clickable phone link in javascript?

my site uses javascript so that when a user clicks a store, a popup with the store info shows up. the store's website and address are clickable but i cant get the same code to work for the phone number

the website code is a bit longer but below is the code for the phone link and the email link. the email link works but not the phone

if(v.telephone != '') {
    info_window_string += "<p class='tel'>"+v.titletel+": <a href= 'tel:"+v.telephone"'>"+v.telephone+"</a></p>";
}

if(v.email != '') {
    info_window_string += "<p class='email'>"+v.titleemail+": <a href='mailto:"+v.email+"'>"+v.email+"</a></p>";
}

i expect that if i open the site in mobile and click the phone link, it'd put it in the phone number field ready to call

Your code is missing an + at the end of the href .

Solution:

"<p class='tel'>"+v.titletel+": <a href= 'tel:"+v.telephone+"'>"+v.telephone+"</a></p>"

Please try it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM