Skip to content

Instantly share code, notes, and snippets.

@laomo
Last active March 4, 2024 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laomo/c160978924dcb52a45977230b0b2a3ba to your computer and use it in GitHub Desktop.
Save laomo/c160978924dcb52a45977230b0b2a3ba to your computer and use it in GitHub Desktop.
打开网页自动向指定号码发送短信
<!-- https://example.com/sms.html?phone=12306&content=999 -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>发送短信</title>
</head>
<body>
<script>
function isAndroid() {
return navigator.userAgent.indexOf('Android') > -1 || navigator.userAgent.indexOf('Adr') > -1;
}
window.onload = function() {
// 获取 URL 参数
const urlParams = new URLSearchParams(window.location.search);
// 获取手机号
const phoneNum = urlParams.get('phone');
// 获取短信内容
const content = urlParams.get('content');
// 跳转到短信页面
if (isAndroid()) {
window.location.href = `sms:${phoneNum}?body=${content}`;
} else {
window.location.href = `sms:${phoneNum}&body=${content}`;
}
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment