The resources

Blog.csdn.net/zhangjing03… Blog.csdn.net/weixin_3408…

Call up the text message on your cell phone

1. Call up text messages

JS

   // The browser's user-agent header
  let u = navigator.userAgent;
  let smsurl = ' ';
  // Text messages need to be transcoded
  smstextArea = encodeURIComponent(textArea)
  if(/(iPhone|iPad|iPod|iOS)/i.test(u))
  {
    smsurl = `sms:${customerPhone}&body=${smstextArea}`
  }else{
    smsurl = `sms:${customerPhone}? body=${smstextArea}`
  }
Copy the code

HTML

<! --Andriod-->
<a href="sms:131***? Body = I am the text">Send a text message</a>
<! --IOS-->
<a href="SMS :131***&body= I am the content of the message">Send a text message</a>
<! Add "#mp.weixin.qq.com" to the end of the URL. Such as company profile page: http://app.xxxxx.com/about.html#mp.weixin.qq.com, then this page inside the tel: can be normal to the dial-up interface - >
Copy the code

The part I wrote

<a id="sms" href="SMS :10086&body= from :xx SMS :xx address :xx">Send a text message</a>
Copy the code
 // The browser's user agent header is used to determine the current client
let u = navigator.userAgent;
// Phone number
const customerPhone = "12312312312"
// Message content
const textArea = "A:" + "\n" + "B:" + "\n" + "C:"
// Message content after transcoding
let smstextArea;
// The url of the last a tag
let smsurl = ' ';
// SMS content needs to be transcoded to support line breaks
smstextArea = encodeURIComponent(textArea)
// Ios and Android SMS send inconsistent & and?
if(/(iPhone|iPad|iPod|iOS)/i.test(u))
{
    smsurl = `sms:${customerPhone}&body=${smstextArea}`
}else{
    smsurl = `sms:${customerPhone}? body=${smstextArea}`
}
// Simulate hit send
let aEl =  document.getElementById("sms")
aEl.href = smsurl

window.location.href = smsurl
Copy the code

Adjust the application

www.jianshu.com/p/21380058d…

Use the positioning

<div id="baidu"></div>
    <div id="google_geo"></div>
    <script>
        function getLocation(){ 
            if (navigator.geolocation){ 
                navigator.geolocation.getCurrentPosition(showPosition,showError); 
            }else{ 
                alert("Browser does not support geolocation."); }}function showPosition(position){
            // Save the latitude and longitude we obtained in the variable
            var latlon = position.coords.latitude+', '+position.coords.longitude; 
            
            / / baidu interface
            var url = "http://api.map.baidu.com/geocoder/v2/?ak=C93b5178d7a8ebdb830b9b557abce78b&callback=renderReverse&location="+latlon+"&output=json&pois=0" 
            $.ajax({ 
                type"GET".dataType"jsonp".url: url, 
                beforeSendfunction(){$("#baidu").html('Locating... '); 
                }, 
                successfunction (data{ 
                    if(data.status==0){ 
                        $("#baidu").html(data.result.formatted_address); }},errorfunction (XMLHttpRequest, textStatus, errorThrown{$("#baidu").html(latlon+"Failed to obtain address location"); }});var  googleUrl ='http://maps.google.cn/maps/api/geocode/json?latlng='+latlon+'&language=CN';
            $.ajax({
                type"GET".dataType"jsonp".url: googleUrl,
                successfunction (data{ 
                    if(data.status=='OK') {var results = data.results; 
                        $.each(results,function(index,array){ 
                            if(index==0){ 
                                $("#google_geo").html(array['formatted_address']); }}); }}})}function showError(error){ 
            switch(error.code) { 
                case error.PERMISSION_DENIED: 
                alert("Location failed, user refused geolocation request"); 
                break; 
                case error.POSITION_UNAVAILABLE: 
                alert("Location failed. Location information is unavailable."); 
                break; 
                case error.TIMEOUT: 
                alert("Location failed, request for user location timed out"); 
                break; 
                case error.UNKNOWN_ERROR: 
                alert("Location failed. Location system failed."); 
                break; 
            } 
        }
        getLocation()
    </script>
Copy the code