问题
I have this function, which pre-fills sms text message on click. This works on Android, but on any version if iOS, it just open new empty window. Any idea, why?
var ua = navigator.userAgent.toLowerCase();
var url;
if (ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1)
{
var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
var ver = [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
if (ver[0] >= 8)
{
url = "sms:&body=" + encodeURIComponent("Hello guys, this is an awesome app! Check it out http://www.myurl.com/webapp/index.html");
}
else
{
url = "sms:;body=" + encodeURIComponent("Hello guys, this is an awesome app! Check it out http://www.myurlcom/webapp/index.html");
}
}
else
url = "sms:?body=" + encodeURIComponent("Hello guys, this is an awesome app! Check it out http://www.muyrl.com/webapp/index.html");
window.open (url,'_system')
回答1:
I tried with a proper HTML link, and it works well on iOS 9.
<a href="sms:+467111111111?&body=Hello my friend">Send SMS</a>
So I can see two potential issues :
- I might not work with
window.open();
- It only works when a number is provided
Edit: I managed to make it work without a number
<a href="sms:?&body=Hello my friend">Send SMS</a>
So it seems to come from window.open()
回答2:
The link below should help you test all the different combinations. Just open it from your cellphone.
What has been working for me is: href="sms://&body=TEST"
list of sms combination format here
来源:https://stackoverflow.com/questions/36360417/window-opensms-works-for-android-but-not-for-ios