gpt4 book ai didi

javascript - 为什么这些共享按钮在 Firefox 中不起作用?

转载 作者:太空宇宙 更新时间:2023-11-04 16:07:23 25 4
gpt4 key购买 nike

我有一组共享按钮,可以在 Safari、Chrome 和 Opera 中使用,但不能在 Firefox 中使用。他们只是在 Firefox 中打开一个新的空白窗口,为什么会这样?

<script type="text/javascript">
function fbCurrentPage()
{window.open("https://www.facebook.com/sharer/sharer.php?u="+escape(window.location.href)+"&t="+document.title, '',
'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');}
function twitterCurrentPage()
{window.open("https://twitter.com/share?u="+escape(window.location.href)+"&t="+document.title, '',
'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');}
function gplusCurrentPage()
{window.open("https://plus.google.com/share?url="+escape(window.location.href)+"&t="+document.title, '',
'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=605,width=400');}
</script>

<div class="social">
<a href="javascript:fbCurrentPage()" class="facebook">Facebook</a>
<a href="javascript:twitterCurrentPage()" class="twitter">Twitter</a>
<a href="javascript:gplusCurrentPage()" class="gplus">Google+</a>
</div>

最佳答案

Firefox 对 target="_blank" 属性感到困惑。 Firefox 打开带有 about:blank URL 的新选项卡,并尝试执行其中一个功能,例如fbCurrentPage 在新打开的选项卡中,但该函数在“空白”文档中不存在。

只需从链接中删除target 属性即可。不需要它,因为函数使用 window.open 打开一个新窗口。

顺便说一句,您的代码根据 HTML 5 规范无效。链接内有按钮。每个spec a 个元素不允许包含 interactive content .

关于javascript - 为什么这些共享按钮在 Firefox 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41772035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com