html 分享链接到facebook telegram twitter whatsapp

在网页中分享一个网页到facebook。

在线测试-分享网页到facebook

 

设置meta

复制代码
      <meta property="twitter:url" content="https://yooul.com/share/share.php?post_uuid=9463af08-660d-11ea-9965-4ffecca286d7&amp;locale=zh-CN&amp;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-分享调试器

分享到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。

posted on   完美前端  阅读(2517)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
历史上的今天:
2020-05-11 dart基础语法-字符串

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示