简体   繁体   中英

ShareThis Button to Open in Popup

I am using Sharethis button for social media sharing. The problem is that when you click on Twitter, Facebook, Linkedin or any other button, it open in new tab. I want it to open in popup window. Is that possible to do. Here is the code I am using.

This goes in head section

    <script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "ur-3a946ea7-4e9c-2bf6-f820-37c233b1bc9c", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>

And this goes in the body of the page.

<span class='st_sharethis_large' displayText='ShareThis'></span>
<span class='st_facebook_large' displayText='Facebook'></span>
<span class='st_twitter_large' displayText='Tweet'></span>
<span class='st_linkedin_large' displayText='LinkedIn'></span>
<span class='st_pinterest_large' displayText='Pinterest'></span>
<span class='st_email_large' displayText='Email'></span>

This did not work either.

<script type="text/javascript">var switchTo5x=true;</ script>
<script type="text/javascript" src=" w.sharethis.com/button/buttons.js"></ script> 
<script type="text/ javascript">
  stLight.options({
    publisher: "ur-3a946ea7-4e9c-2bf6- f820-37c233b1bc9c", 
    popup: 'true' 
    doNotHash: false, 
    doNotCopy: false, 
    hashAddressBar: false
 });
 </script>

除了popup选项之外,您还需要在调用stLight.options()时将servicePopup选项设置为true

<script charset="utf-8" type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script charset="utf-8" type="text/javascript">
    stLight.options({
        "publisher":"####",
        "doNotCopy":false,
        "hashAddressBar":false,
        "doNotHash":false,
        "servicePopup":true
    });
</script>

I got this script working with ShareThis plugin, with:

"servicePopup":true

The problem is the button.js plugin that you are using.. If you had a link you could specify WHERE to open it, or with JS

window.open("www.youraddress.com","_self")

But since you're using a pre-made plugin you can't change that.

You could create your own script to open a specific page on class click with something like

$('.stack').click(function(){
    window.location = 'www.stackoverflow.com';
});

EDIT: Or as you can see from the comment on the question, that plugin supports option flags. My bad, haven't checked it.

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