简体   繁体   中英

Auto append facebook share dialog (website)

I am trying to make a auto append facebook share dialog in my site, I have try below code and It can show the dialog if I click the image. Is there any method to show the share dialog without any button click? (show when page load) Thanks!

Below is my code

<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId : 'myappid',
            status : true, // check login status
            cookie : true, // enable cookies to allow the server to access the session
            xfbml : true // parse XFBML
        });
    };

    (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    }());
</script>

<script type="text/javascript">
    $(document).ready(function(){
        $('#submitbtn').live('click', function(e){
            FB.ui(
                {
                method: 'feed',
                name: 'My title',
                link: 'mylink',
                picture: 'http://my.jpg',
                caption: 'Come to Play',
                description: 'Come to Play',
                message: ''
            });
        });
    });
</script>
<img src = "share_button.png" id = "share_button">

if want to make it appear without any click, u can use "onmouseover" event on btn or image.

Or if you want it to appear after page load, Just call the function outside of click event. For example,

var example = function(){
    FB.ui(
    {
       method: 'feed',
       name: 'My title',
       link: 'mylink',
       picture: 'http://my.jpg',
       caption: 'Come to Play',
       description: 'Come to Play',
       message: ''
    });
 }

$(document).ready(function(){
    example();
}

Hope meet your taste.

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