javascript - 如何在手机网站上制作转发按钮,使用内部转发功能
问题描述
我需要在网站上实现当前页面链接共享按钮,我尝试使用 webshare api 来实现,但在所有设备上我都收到警告,浏览器版本已过时,我需要更新它。你能建议任何其他方法吗?
var shareButton = document.getElementById('share-button');
shareButton.addEventListener('click', function () {
if (navigator.share) {
console.log("Your browser support")
navigator.share({
title: "title",
text: "text",
url: window.location.href,
})
.then(function () {
console.log("Success")
})
.catch(function () {
console.log("Error")
})
} else {
alert("Your browser version is out of date")
}
})'''
<div class="share-button-plugin mt-30">
<button id="share-button"><i class="fa fa-share-alt"></i>Share</button>
</div>
解决方案
在 Firefox 网站 ( https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share ) 上写着你应该使用navigator.canShare()
另外,还有一个说明:
安全上下文。此功能仅在安全上下文 (HTTPS)、部分或所有支持的浏览器中可用。
由于浏览器兼容性差,我一般不会使用此功能:
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share#Browser_compatibility
推荐阅读
- apache-kafka - Confluent Kafka Azure EventHub 源连接器出错
- java - 将 PDDocument 与 try-with-resources 一起使用是否可以保证文件已完全写入?
- javascript - 每次点击都会增加数字
- excel - 我不希望我的 VBA 代码更改工作表
- apache - pi raspbian buster apache2 www-data 禁止在不同的目录 2021
- javascript - 系统信息仅待处理,在vue中不显示任何结果
- .htaccess - htaccess 删除 php 以获得干净的 SEO 友好 url
- c# - MVVC - 使用 ViewBag 和控件传递参数的问题
- c# - 使用部分类添加注释/元数据
- c# - .NET Core 控制台的 AcquireTokenInteractive 不提供响应