-->

使用jQuery动态改变2007-06-18网址(Change AddThis url dynami

2019-08-17 12:25发布

我试图动态改变前页发送的URL。 当用户改变一个元素,它包含更新的自定义网址,使他们能够返回到该网址,并继续/查看他们的工作文字区域。

我创建了以下这样一个前页按钮(从他们的API文档):

var addthis_share = {url:"http://www.johndoe.com"}
$(document).ready(function(){
    var tbx = document.getElementById("toolbox"),
    svcs = {email: 'Email', print: 'Print', facebook: 'Facebook', expanded: 'More'};
    for (var s in svcs) {
        tbx.innerHTML += '<a class="addthis_button_'+s+'">'+svcs[s]+'</a>';
    }
    addthis.toolbox("#toolbox");
});

然后,当网址更新我想更新前页共享网址如下所示:

function updateURL(){
    ...get some variables here and generate a new url
    var newURL="http://the.url.i.want.to.share.com";
    $('#tagUrl').val(newURL);
    //addthis_share = {url:newURL}
    addthis_share = {url:newURL}
    addthis.toolbox("#toolbox");
} 

原来的按钮如何产生,并包含正确的网址,但该网址更新功能执行时的前页共享网址是不会得到更新。 我怎样才能迫使它来更新前页网址是什么?

Answer 1:

如果你想改变URL前页的HTML被加载后(在阿贾克斯还是有些用户事件的情况下),请使用以下的黑客。 前页的API被分解为上[09/04/13 11:42:24 AM]晴天jhunjhunwala:

addthis.update('share', 'url', 'http://www.sourcen.com'); 
addthis.url = "http://www.sourcen.com";                
addthis.toolbox(".addthis_toolbox");

http://www.sourcen.com --->新网址



Answer 2:

它是如此简单:

addthis.update('share', 'url', "http://www.example.com");
addthis.update('share', 'title', "Example Domain Title");
addthis.update('share', 'description', "Hello, I am a description");

干杯,加里



Answer 3:

2007-06-18提供addthis.update(“共享”,“URL”,值)函数(但它是在IE8的童车功能); 试试这个:

for(var i = 0; i < addthis.links.length; i++){
    addthis.links[i].share.url= "new url";
}


Answer 4:

<span id="share-obj" addthis:url="" addthis:title=""></span>

<script type="text/javascript">
    var shareConfig = {url: '', title: ''};

    addthis.button('#share-obj', {}, shareConfig);

    addthis.addEventListener('addthis.menu.open', function(event){
        if ( ! event.data.element.isSameNode($('#share-obj')[0])) {
            return;
        }

        event.data.share.title = shareConfig.title;
        event.data.share.url = shareConfig.url;
    });

    // in updateURL() or any other place during runtime...
    function updateURL() {
        shareConfig.url = 'http://different.url';
        shareConfig.title = 'Title changed dynamically...';
    }
</script>

我用了一个全局变量shareConfig来追踪URL和标题的配置。 我有多个按钮前页在网页中,每个分享不同的内容。 因此,我添加了一个isSameNode ,以确保我只更新我想要的按钮。

虽然URL和标题动态变化, addthis:urladdthis:title属性必须存在于按钮( <span>否则将无法正常工作。



Answer 5:

步骤1:准备AJAX内容被装载有其他HTML;

<div class="addthis_sharing_toolbox-CUSTOM" data-url="<?php my_dynamic_link(); ?>" data-title="<?php my_dynamic_title(); ?>">
    <a class="addthis_button_email" style="cursor:pointer"></a>
    <a class="addthis_button_facebook" style="cursor:pointer"></a>
    <a class="addthis_button_twitter" style="cursor:pointer"></a>
    <a class="addthis_button_linkedin" style="cursor:pointer"></a>
</div>

第2步:准备我的fancybox AJAX的设置;

$('.popUpBtn').fancybox({
    //....other fancybox settings can go here...
    //....
    afterShow   : function(current, previous){
        //addthis.init();
        addthis.update('share', 'url', $('.fancybox-inner .addthis_sharing_toolbox-CUSTOM').data('url'));
        addthis.update('share', 'title', $('.fancybox-inner .addthis_sharing_toolbox-CUSTOM').data('title'));
        //addthis.update('share', 'description', "Hello, I am a description");
        addthis.toolbox('.addthis_sharing_toolbox-CUSTOM'); //-->Important: this selector should not be anything from the addthis settings page; We can choose any other names like normal selectors;
    }
});

内部的上述线“afterShow()”函数是重要的是保持一个音符;



Answer 6:

在自定义按钮:

<a class="addthis_button_compact" >
   <img src="./images/share.png" width="36" height="36" border="0" alt="Share" />
</a>

头部:

<meta property="og:title" content="YOUR TITLE" />
<meta property="og:description" content="YOUR DESCRIPTION" />
<meta property="og:image" content="YOUR IMAGE URL" />

正文部分:对我来说,我使用的PHP我定身属性,像这样。

<body
      data-url="<?php echo basename($_SERVER['REQUEST_URI']); ?>"
      data-title="<?php echo $info->record_info->brand; ?>"
      data-description="<?php echo $info->record_info->description; ?>"
      data-media="<?php echo ./uploads/logos/<?php echo $info->record_info->logo; ?>"
>

要更新动态内容(JS部分):

<script>
    addthis.update('share', 'url', $('body').data('url')); // will set the URL
    addthis.update('share', 'title', $('body').data('title')); // will set the title
    addthis.update('share', 'description', $('body').data('description')); // will set the description
    addthis.update('share', 'media', $('body').data('media')); // will set the image if you are sharing
</script>


文章来源: Change AddThis url dynamically with jQuery