Jump to content

How to put custom body on <a href="sms link?


edmon
Go to solution Solved by dodgeitorelse3,

Recommended Posts

I am trying to create simple web that user can send their location via SMS using  geolocation . The problem is I couldn't put link to SMS body.

How can I put link on it? Any suggestion please, here is my code:

 

<html>
<head>
    <title>Please SEND your location</title>
    <script>
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function (position) {
                const geoLocation = {
                    latitude: position.coords.latitude,
                    longitude: position.coords.longitude,
                };
                console.log('Their location --->', geoLocation);
            });
        }
    </script>
    <p>
        <a href="sms:+123456789?&body=https://www.google.com/maps/search/?api=1&query=${geoLocation.latitude},${geoLocation.longitude}">Sending a location</a>
     </p    
</html>

 

Link to comment
Share on other sites

On 9/6/2024 at 11:18 PM, requinix said:

You have code that is able to get their location. You need to take that location data and put it into the link at that time - you can't put it in there ahead of time.

Take a look at MDN's geolocation examples for something that's actually very close to what you want to do.

Hi there. 

Yes I got the location. But I have no idea how to call the that link outside of the <script> tab. Using Js or imap or what can I use? Any suggestion please

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.