html 分享链接到facebook telegram twitter whatsapp
在网页中分享一个网页到facebook。
设置meta
<meta property="twitter:url" content="https://yooul.com/share/share.php?post_uuid=9463af08-660d-11ea-9965-4ffecca286d7&locale=zh-CN&hide=0"> <meta property="twitter:type" content="article"> <meta property="twitter:title" content="1111"> <meta property="twitter:description" content="1111"> <meta property="twitter:image" content="https://qnidyooulimage.mmantou.cn/FmQeJquE5Q_oMbGD_Td0Q8BjoRve.jpg?imageView2/2/w/200/h/200/interlace/1|imageslim"> <meta name="twitter:image:src" content="https://qnidyooulimage.mmantou.cn/FmQeJquE5Q_oMbGD_Td0Q8BjoRve.jpg?imageView2/2/w/1200/interlace/1|imageslim">
Facebook的meta tags
<meta property="fb:app_id" content="748486512258997"> <meta property="og:url" content="https://www.baidu.com"> //自定义分享的链接 <meta property="og:type" content="article"> <meta property="og:title" content="网页title"> <meta property="og:description" content="111descripton"> <meta property="og:image" content="https://qnidyooulimage.mmantou.cn/FmQeJquE5Q_oMbGD_Td0Q8BjoRve.jpg?imageView2/2/w/200/h/200/interlace/1|imageslim"> // 自定义图片
-
<meta property="og:url" content="https://www.eoway.cn/show/share/facebook.html" /> // 自定义需要分享的链接 <meta property="og:type" content="article" /> <meta property="og:title" content="这是一个网页title" /> <meta property="og:description" content="这是网页的description" /> <meta property="og:image" content="http://oss.eoway.cn/upload/files/2020-05-02-20-37-08-rn383.jpg" /> // 自定义图片
- 以上mata标签只需要编辑content的内容
- url不可以带参数
// 错误的url
https://www.eoway.cn/show/share/facebook.html?id=123
测试您的标记
设置好后,可以在调试器中检测网页设置
分享到facebook
var url = 'https://www.eoway.cn/show/share/facebook.html'
#### 分享功能的实现
打开新窗口并设置URL
let windowObjectReference = window.open(); windowObjectReference.location.href = 'https://www.facebook.com/sharer/sharer.php?u='+ url; // 注意:url必须为meta设置的url
分享功能函数
share(type) { let windowObjectReference = window.open(); // 把域名地址当做url的参数,需要encodeURIComponent编码 let url = encodeURIComponent(this.share_link + '?code=') + this.userinfo.share_code + encodeURIComponent('DIF Investment and financial management to realize the dream of wealth!'); // 根据分享的类型决定分享的URL if(type === 'facebook') { windowObjectReference.location.href = 'https://www.facebook.com/sharer/sharer.php?u=' + url; } else if(type === 'telegram') { windowObjectReference.location.href = 'https://t.me/share/url?url=' + url; } else if(type === 'twitter') { windowObjectReference.location.href = 'https://twitter.com/intent/tweet?text=' + url; // https://twitter.com/who 跳转到个人信息页面 可关注 who是用户名账号 } else if(type === 'whatsapp') { windowObjectReference.location.href = 'https://api.whatsapp.com/send?text=' + url; } }
代码实现了一个分享功能,用户可以选择不同的社交平台进行分享。通过使用`window.open()`方法,可以在新窗口中打开相应的分享链接,从而允许用户在所选的社交平台上分享指定的URL。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2020-05-11 dart基础语法-字符串