CyberJunkie
CyberJunkie

Reputation: 22684

HTML5 - URL characters stripped when using sms href

I'm using the following format to open the SMS view on mobile phones from a browser

window.location.href = "sms:[phone number]?body=" + message;

I want to add the following google map URL in the SMS body

var myAddress = "https://maps.google.com/maps?q=North+Miami,+FL+33190,+USA"
window.location.href = "sms:11122233333?body="+myAddress;

The SMS view opens fine on the phone and the SMS body is populated but the + signs are stripped out and replaced with spaces. I don't know what's causing this... How can this be prevented?

Upvotes: 0

Views: 493

Answers (1)

Prakash GPz
Prakash GPz

Reputation: 1523

encode the myAdress variable, before adding it to main url

    var myAddress = encodeURIComponent( "https://maps.google.com/maps?q=North+Miami,+FL+33190,+USA" );
    window.location.href = "sms:11122233333?body="+myAddress;

Upvotes: 1

Related Questions