原文地址 https://github.com/fa-ge/NativeShare/blob/master/README.md
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
<meta name="description" content="NativeShare 是一个整合了各大移动端浏览器调用原生分享的插件!!!">
<title>NativeShare demo</title>
<style>
html,
body {
height: 100%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
button {
padding: 15px;
}
</style>
</head>
<body>
<div>
<button onclick="call()">通用分享</button>
<button onclick="call('wechatFriend')">微信好友</button>
<button onclick="call('wechatTimeline')">朋友圈</button>
<button onclick="call('qqFriend')">QQ</button>
<button onclick="call('qZone')">QQ空间</button>
<button onclick="call('weibo')">微博</button>
<button onclick="setTitle('fa-ge NativeShare')">设置标题</button>
</div>
<script type="text/javascript" src="../NativeShare.js"></script>
<script>
var nativeShare = new NativeShare()
var shareData = {
title: 'NativeShare',//分享标题
desc: 'NativeShare是一个整合了各大移动端浏览器调用原生分享的插件',//描述
link: 'https://github.com/fa-ge/NativeShare',//分享的url链接
icon: 'https://pic3.zhimg.com/v2-080267af84aa0e97c66d5f12e311c3d6_xl.jpg',
// 不要过于依赖以下两个回调,很多浏览器是不支持的
success: function() {
alert('success')
},
fail: function() {
alert('fail')
}
}
nativeShare.setShareData(shareData)
function call(command) {
try {
nativeShare.call(command)
} catch (err) {
// 如果不支持,你可以在这里做降级处理
alert(err.message)
}
}
function setTitle(title) {
nativeShare.setShareData({
title: title,
})
}
</script>
</body>
</html>