简体   繁体   中英

Facebook sharing script not working

I am using this script for sharing options.This works well on single.php . Problem is on home page ,where i have 10 posts..For each post there is a sharing button. But when user clicks on any post to share, then only the last post in the loop gets shared

    <script>
function facebook()
{
window.open("http://facebook.com/sharer.php?app_id=1433580610197489&sdk=joey&u=<?php the_permalink(); ?>","_blank","toolbar=no, scrollbars=no, resizable=yes, top=500, left=500, width=650, height=540");
}

function google()
{
window.open("https://plus.google.com/share?url=<?php the_permalink(); ?>","_blank","toolbar=no, scrollbars=no, resizable=yes, top=500, left=500, width=650, height=540");
}
function twitter()
{
window.open("http://twitter.com/home?status=<?php the_permalink(); ?>","_blank","toolbar=no, scrollbars=no, resizable=yes, top=500, left=500, width=650, height=540");
}

</script> 

                              <a title="Facebook" onclick="facebook()" ><i class="fa fa-facebook"></i></a>
                              <a title="Twitter" onclick="twitter()" ><i class="fa fa-twitter"></i></a>
                              <a title="Google+" onclick="google()" ><i class="fa fa-google-plus"></i></a> 

do i understand right, that you have something like this:

for (var i=0; i < 10; i++) {
function facebook() { ... }
[...]
<a title="Facebook" onclick="facebook()" ><i class="fa fa-facebook"></i></a>                    
}

if so you override the facebook() function every time.

Try something like this:

function facebook(permalink) {
window.open("http://facebook.com/sharer.php?app_id=1433580610197489&sdk=joey&u=" + permalink,"_blank","toolbar=no, scrollbars=no, resizable=yes, top=500, left=500, width=650, height=540");
}

<a title="Facebook" onclick="facebook('<?php the_permalink(); ?>')" ><i class="fa fa-facebook"></i></a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM