我需要在网站上实现当前页面链接共享按钮,我试图使用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>
发布于 2020-12-21 20:59:28
在火狐网站( 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
https://stackoverflow.com/questions/65391069
复制相似问题