我正在尝试创建一个发送文本消息的按钮。我被赋予了代码,我只是不知道该怎么处理它。请帮忙!
iPhone
href = "sms://+15558675309/&body=TextHere"
Android系统
href = "sms://+15558675309/?body=TextHere"
如果你想知道,“我怎样才能确定他们使用的是iPhone还是Android?”
给你:
function getMobileOperatingSystem() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
if ( userAgent.match( /iPad/i ) || userAgent.match( /iPhone/i ) || userAgent.match( /iPod/i ) ) { return \'iOS\'; }
else if ( userAgent.match( /Android/i ) ) { return \'Android\'; }
else { return \'unknown\'; }
}
Then you can wrap the above SMS syntax like this:
var message_text = \'Pre-filled message goes here\'
if (device == \'iOS\') {
href = "sms://+15558675309/&body=" + encodeURI(message_text);
}
if (device == \'Android\') {
href = "sms://+15558675309/?body=" + encodeURI(message_text);
}