window.open("sms:...")适用于android,但不适用于ios [英] window.open("sms:...") works for android but not for ios
本文介绍了window.open("sms:...")适用于android,但不适用于ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有此功能,可在点击时预先填写短信.这在Android上有效,但是在任何版本(如果是iOS)上,它只会打开新的空白窗口.知道为什么吗?
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')
推荐答案
我尝试使用正确的HTML链接,并且在iOS 9上运行良好.
I tried with a proper HTML link, and it works well on iOS 9.
< a href ="sms:+467111111111?& body =你好我的朋友">发送短信</a>
所以我可以看到两个潜在的问题:
So I can see two potential issues :
- 我可能无法使用
window.open();
- 仅在提供电话号码时有效
编辑:我设法使其不带数字运行
I managed to make it work without a number
< a href ="sms:?& body =你好我的朋友">发送短信</a>
所以它似乎来自 window.open()
这篇关于window.open("sms:...")适用于android,但不适用于ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文