2017-01-20 61 views
1

我有一套共享按鈕,在Safari,Chrome和Opera中工作,但不是Firefox。他們只是在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> 

回答

1

Firefox被target="_blank"屬性混淆。 Firefox使用about:blank URL打開新選項卡並嘗試執行其中一個功能,例如fbCurrentPage在新打開的選項卡中,但該功能不存在於「空白」文檔中。

只需從鏈接中刪除target屬性即可。這是不需要的,因爲功能使用window.open,它打開一個新窗口。

而在附註中,您的代碼在HTML 5規範方面無效。鏈接中有按鈕。 a元素每spec不允許包含interactive content

+0

謝謝!現在起作用了,我已經更新了上面的那些位。 – Ash

相關問題