Search code examples
javascriptfirefoxsharingsocial-media

Why do these share buttons not work in a Firefox?


I have a set of share buttons which work in Safari, Chrome and Opera but not Firefox. They just open a new blank window in Firefox why would that be?

<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> 

Solution

  • Firefox gets confused by the target="_blank" attribute. Firefox opens new tab with about:blank URL and tries to execute one of the functions, e.g. fbCurrentPage in the newly opened tab, but the function doesn't exist in the "blank" document.

    Just remove the target attribute from links. It's not needed since the functions use window.open which opens a new window.

    And on a side note, your code is invalid in terms of HTML 5 spec. You have buttons inside links. a elements per spec are not allowed to contain interactive content.