dongzhi8487 2013-11-06 14:10
浏览 17
已采纳

如何让共享按钮使用当前的URL?

    <a href="http://www.linkedin.com/shareArticle?url=MY_URL" class="in-share-button" target="_blank"> 
<img src="my_img" alt="linkedin share button" title="Share on Linked In" /> </a>

This is currently my share button. I want it to share the url that's currently in the address bar, and not a fixed preset url like it does atm.

I found

<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo $url; ?>

what seems to fit my needs. But when I change "MY_URL" with this it just creates a link to the main page of my website.

The URL it SHOULD display looks like "www.myurl.de/#/id_of_a_post". I feel like the # is the problem. . .

can you provide me any help with this?

  • 写回答

3条回答 默认 最新

  • duanchen1937 2013-11-06 15:45
    关注

    It just worked another way.

    My friend created a script that saves the ID of the individual posts:

    (function(){
        var numbers = document.URL.match(/\d+/g);
                        if(numbers !=  null){
                            $('#right-col').addClass('shown').removeClass('hidden');
                            $('#left-col').addClass('colPositioning');                        
                            $('#right_'+numbers).addClass('shown1');                         
                        ;}
    }());
    

    Afterwards I was able to use:

    <a href="https://twitter.com/share?url=my_url/%23/?p=<?php the_id();?>" class="twitter-share-button" target="_blank"><img src="img_src"></a>
    

    The trick about it was to replace the # with the "%23". I think it's called encodedURI.

    What do you guys think about this solution?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!