{"id":13835346,"url":"https://github.com/fa-ge/NativeShare","last_synced_at":"2025-07-10T07:31:39.381Z","repository":{"id":57308858,"uuid":"93940305","full_name":"fa-ge/NativeShare","owner":"fa-ge","description":"NativeShare是一个整合了各大移动端浏览器调用原生分享的插件","archived":false,"fork":false,"pushed_at":"2020-11-23T03:58:19.000Z","size":151,"stargazers_count":898,"open_issues_count":61,"forks_count":329,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-06-22T20:40:57.585Z","etag":null,"topics":["javascript","javascript-library","native","share"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fa-ge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-10T13:18:53.000Z","updated_at":"2025-06-06T15:20:49.000Z","dependencies_parsed_at":"2022-09-01T09:03:12.484Z","dependency_job_id":null,"html_url":"https://github.com/fa-ge/NativeShare","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fa-ge/NativeShare","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fa-ge%2FNativeShare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fa-ge%2FNativeShare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fa-ge%2FNativeShare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fa-ge%2FNativeShare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fa-ge","download_url":"https://codeload.github.com/fa-ge/NativeShare/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fa-ge%2FNativeShare/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264545167,"owners_count":23625404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","javascript-library","native","share"],"created_at":"2024-08-04T14:01:00.019Z","updated_at":"2025-07-10T07:31:38.594Z","avatar_url":"https://github.com/fa-ge.png","language":"JavaScript","readme":"原文地址 [https://github.com/fa-ge/NativeShare/blob/master/README.md](https://github.com/fa-ge/NativeShare/blob/master/README.md)\n\n### 起因\n\n最近有一个活动页需要在移动端浏览器分享网页到微信，QQ。虽然每一个浏览器都有分享到微信的能力，但不是每个都提供接口供网页来调用。即使有提供，浏览器暴露出的api也各不相同，而我写[NativeShare](https://github.com/fa-ge/NativeShare)的目的只是为前端开发者提供一致的api来调用浏览器的原生分享组件。大小uglify + gzip = 4k。\n\n\n\n### 兼容性(毫无疑问是兼容浏览器最多的插件了)\n\n- **移动端几乎所有浏览器都支持分享到QQ和QQ空间**\n- QQ浏览器\n- UC浏览器\n- 微信自带浏览器\n- QQ自带浏览器\n- QQ空间APP\n- 百度浏览器\n- ios 搜狗浏览器\n- 支持分享到web微博\n- 支持safari,chome浏览器(页面地址必须是https)\n\n存在的问题\n\n* 安卓的QQ自带浏览器不支持.com以外的域名后缀。可能会支持.cn,.com.cn，但明确不支持.me,.io这个具体可以自己测试。\n* 安卓的QQ自带浏览器分享url必须跟页面url同一个域名，否则所有设置不生效。\n* 安卓的QQ自带浏览器无法直接分享\n* 虽然几乎所有的浏览器都支持分享到QQ和QQ空间，但是webview中基本都会不支持。我也很难判断当前浏览器是否支持，浏览器是否唤起QQ APP我也很难判断，所有除了上述支持的浏览器，APP外其他情况调用分享到QQ我也会抛出异常。\n* UC浏览器安卓端不能设置icon\n* 百度浏览器，百度APP不能直接分享\n* QQ空间APP，微信自带浏览器只能设置文案，分享需要用户手动点击右上角\n\n\n\n### 示例\n[demo](https://fa-ge.github.io/NativeShare/demo/index.html)\n\n![demo](https://fa-ge.github.io/NativeShare/demo/demo.png)\n\n### npm包安装\nnpm install --save nativeshare\n\n### 使用\n支持ES6模块,AMD，CMD引入\n如果你的项目没有模块化。你也可以直接用script标签引入NativeShare.js。可以参考[demo](https://fa-ge.github.io/NativeShare/demo/index.html)\n```javascript\nimport NativeShare from 'nativeshare'\n\n// 先创建一个实例\nvar nativeShare = new NativeShare()\n// 如果你需要在微信浏览器中分享，那么你需要设置额外的微信配置\n// 特别提示一下微信分享有一个坑，不要分享安全域名以外的链接(具体见jssdk文档)，否则会导致你配置的文案无效\n// 创建实例应该带参数\nvar nativeShare = new NativeShare({\n    wechatConfig: {\n        appId: '',\n        timestamp: '',\n        nonceStr: '',\n        signature: '',\n    },\n  \t// 让你修改的分享的文案同步到标签里，比如title文案会同步到\u003ctitle\u003e标签中\n\t// 这样可以让一些不支持分享的浏览器也能修改部分文案，默认都不会同步\n  \tsyncDescToTag: false,\n  \tsyncIconToTag: false,\n  \tsyncTitleToTag: false,\n})\n\n// 你也可以在setConfig方法中设置配置参数\nnativeShare.setConfig({\n    wechatConfig: {\n        appId: '',\n        timestamp: '',\n        nonceStr: '',\n        signature: '',\n    }\n})\n\n\n// 设置分享文案\nnativeShare.setShareData({\n    icon: 'https://pic3.zhimg.com/v2-080267af84aa0e97c66d5f12e311c3d6_xl.jpg',\n    link: 'https://github.com/fa-ge/NativeShare',\n    title: 'NativeShare',\n    desc: 'NativeShare是一个整合了各大移动端浏览器调用原生分享的插件',\n    from: '@fa-ge',\n})\n\n// 唤起浏览器原生分享组件(如果在微信中不会唤起，此时call方法只会设置文案。类似setShareData)\ntry {\n\tnativeShare.call()\n    // 如果是分享到微信则需要 nativeShare.call('wechatFriend')\n    // 类似的命令下面有介绍\n} catch(err) {\n  // 如果不支持，你可以在这里做降级处理\n}\n```\n\n### API\n\nNativeShare一共只有五个实例方法\n\n* getShareData() 获得分享的文案\n* setShareData() 设置分享的文案\n* call(command = 'default', [options]) 调用浏览器原生的分享组件\n* setConfig() 设置配置参数和new NativeShare()中设置的一样\n* getConfig() 获得配置参数\n\n```javascript\n{\n    icon: '',\n    link: '',\n    title: '',\n    desc: '',\n    from: '',\n      \n    // 以下两个个回调目前只有在微信和百度APP中很好的支持\n    success: noop,\n    fail: noop,\n      \n    // 只有微信支持\n    trigger: noop,\n}\n```\n\n调用call方法时第一个参数是指定用什么命令调用分享组件。目前支持6个命令。分别是\n\n* default 默认，调用起底部的分享组件，当其他命令不支持的时候也会调用该命令\n* wechatTimeline 分享到朋友圈\n* wechatFriend 分享给微信好友\n* qqFriend 分享给QQ好友\n* qZone 分享到QQ空间\n* weibo 分享到微博\n\n\n### 交流\n如果你是浏览器开发者或者你知道其他浏览器调用分享的方式，请务必一定要告诉我。\n","funding_links":[],"categories":["目录"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffa-ge%2FNativeShare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffa-ge%2FNativeShare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffa-ge%2FNativeShare/lists"}