分享到社交媒体

 <script>
      // 通用的分享窗口打开方法
      function openShareWindow(url, width = 750, height = 600) {
          const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
          const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
          
          const systemZoom = window.innerWidth / window.screen.availWidth;
          const left = (window.screen.availWidth - width) / 2 / systemZoom + dualScreenLeft;
          const top = (window.screen.availHeight - height) / 2 / systemZoom + dualScreenTop;
          
          const features = `scrollbars=yes,width=${width},height=${height},top=${top},left=${left}`;
          window.open(url, 'share', features);
      }
      // // 添加自定义Toast提示函数
      function showToast(message, type = 'success') {
        // 创建toast元素
        const toast = document.createElement('div');
        toast.className = `custom-toast ${type}`;
        
        // 设置内容
        toast.innerHTML = `
        <div class="toast-content">
            <span class="toast-icon">${type === 'success' ? '✓' : '!'}</span>
            <span class="toast-message">${message}</span>
        </div>
    `;
    
    // 添加到页面
    document.body.appendChild(toast);
    
    // 添加显示类名
    setTimeout(() => toast.classList.add('show'), 10);
    
    // 自动移除
        setTimeout(() => {
            toast.classList.remove('show');
            setTimeout(() => toast.remove(), 300);
        }, 2000);
}
    // 分享到 LinkedIn
    function shareToLinkedIn() {  
      const url = encodeURIComponent(window.location.href);
      const title = encodeURIComponent(JSON.parse(`{$solution.title|json_encode}`));
      const summary = encodeURIComponent(JSON.parse(`{$solution.description|json_encode}`));
      const source = encodeURIComponent("安东在线服务");
      const shareUrl = 'https://www.linkedin.com/sharing/share-offsite/?' +
        'url=' + url +
        '&title=' + title +
        '&summary=' + summary +
        '&source=' + source;
      // 直接在当前窗口打开
      window.location.href = shareUrl;
    }

// 分享到 Twitter
function shareToTwitter() {
      const url = encodeURIComponent(window.location.href);
      const title = encodeURIComponent(JSON.parse(`{$solution.title|json_encode}`));
      const shareUrl = 'https://twitter.com/intent/tweet?url=' + url + '&text=' + title; 
      // 直接在当前窗口打开
      window.location.href = shareUrl;
}
    // 分享到微信   // 
function copyToWechat() {
      const url = window.location.href; // 获取当前网页链接

      // 备用方法:创建一个临时输入元素来复制链接
      const tempInput = document.createElement('input');
        tempInput.value = url;
        document.body.appendChild(tempInput);
        tempInput.select();
        try {
          document.execCommand('copy');
          showToast('链接已复制,请到微信中粘贴');
        } catch (err) {
          console.error('复制失败:', err);
          showToast('复制失败,请手动复制');
        }
        document.body.removeChild(tempInput);
    }
    function shareToWhatsApp() {
        const title = encodeURIComponent(JSON.parse(`{$solution.title|json_encode}`));
        const url = encodeURIComponent(window.location.href);
        const text = encodeURIComponent(document.title);
        const shareUrl = 'https://api.whatsapp.com/send?text=' + text + '%20' + title + '%20' + url;
        window.location.href = shareUrl;
    }

  </script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

桔梗人柱力

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值