简体   繁体   English

点击共享按钮时打开新标签页

[英]Open new tab when click the share buttons

I have implemented few social media share buttons. 我实现了一些社交媒体共享按钮。 It is working fine. 一切正常。 When i click on those buttons it open a popup. 当我单击这些按钮时,它将打开一个弹出窗口。 But i need them to open in new tab. 但是我需要它们在新标签页中打开。 Can anyone help me out how to do it? 有人可以帮我怎么做吗? And i want those button to be round using images/svg. 而且我希望这些按钮使用图像/ svg是圆形的。 Here is my Codes 这是我的密码

<div class="fb-share-button" 
    data-href="<?= $url ?>" 
    data-layout="icon"
    data-size="large"
    data-mobile-iframe="true"></div>

<a class="twitter-share-button"
    href="https://twitter.com/intent/tweet"
    data-text="'<?= $quote ?>..' "
    data-url="<?= $url ?>"
    data-size="small"> Tweet </a>

<a data-pin-do="buttonPin"
    href="https://www.pinterest.com/pin/create/button/"
    data-pin-url="<?= $url ?>"
    data-pin-media="<?= $image ?>"
    data-pin-description="<?= $quote ?>"
    data-pin-shape="round"></a>

<div id="fb-root"></div>
<script>
    (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.0";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
</script>

<script>
    window.twttr = (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0],
        t = window.twttr || {};
        if (d.getElementById(id)) return t;
        js = d.createElement(s);
        js.id = id;
        js.src = "https://platform.twitter.com/widgets.js";
        fjs.parentNode.insertBefore(js, fjs);

        t._e = [];
        t.ready = function(f) {
        t._e.push(f);
        };

        return t;
    }(document, "script", "twitter-wjs"));
</script>

<script
    type="text/javascript"
    async defer
    src="//assets.pinterest.com/js/pinit.js"
></script>

for open a link in new tab, add 'target' attribute to that anchor or button and set its value to '_blank'. 要在新标签页中打开链接,请将“ target”属性添加到该锚点或按钮,并将其值设置为“ _blank”。

example: 例:

<a class="twitter-share-button"
href="https://twitter.com/intent/tweet"
data-text="'<?= $quote ?>..' "
data-url="<?= $url ?>"
data-size="small"
target="_blank"> Tweet </a>

When i click on those buttons it open a popup. 当我单击这些按钮时,它将打开一个弹出窗口。 But i need them to open in new tab. 但是我需要它们在新标签页中打开。 Can anyone help me out how to do it? 有人可以帮我怎么做吗? And i want those button to be round using images/svg. 而且我希望这些按钮使用图像/ svg是圆形的。

You can not do that while using these plugins; 使用这些插件时,您无法做到这一点; they render their own elements with their own style and their own script logic attached, and you have no access to them. 它们使用自己的样式和附加的脚本逻辑来呈现自己的元素,并且您无权访问它们。

Use HTML and CSS to create your own buttons/links instead, and then use the methods to share by simply calling a URL these networks provide - a comprehensive list can be found here, https://github.com/bradvin/social-share-urls 改用HTML和CSS创建您自己的按钮/链接,然后使用这些方法通过简单地调用这些网络提供的URL进行共享-可以在这里找到完整列表https://github.com/bradvin/social-share -urls

I had to pass all of those code manually to get my desire result, here is my code: 我必须手动传递所有这些代码才能获得想要的结果,这是我的代码:

<a href="http://www.facebook.com/share.php?u=<?= $url ?>" target="_blank" style="display: inline-block;">
    <img src="facebook_circle.png" style="width: 26px;">
</a>

<a href="https://twitter.com/share?url=<?= $url ?>&text='<?= $quote ?>'" target="_blank" title="Share on Twitter" style="display: inline-block;">
    <img src="twitter_circle.png" style="width: 26px;">
</a>

<a target="_blank" href="http://pinterest.com/pin/create/bookmarklet/?url=<?= $url ?>&media=<?= $image ?>&description=<?= $quote ?>" style="display: inline-block;">
    <img src="pinterest_circle.png" style="width: 26px;">
</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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