Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Update URL for Dynamic URLs

ShareThis does not seem to have a way to update URL which dynamically changes for html5 history-enabled or ajax-driven sites.

I tried this function to update it but URL remains original:

function initShareThis(){
    var el = document.getElementById("lotShareThis");
    var target = el.firstChild;
    for (var i in stWidget.shareables) {
        if (stWidget.shareables[i].element === target) {
            stWidget.shareables[i].url = window.location.href;
            break; 
        } 
    }
    el.firstChild.onclick();
}

I also tried this but no any effect:

    stWidget.addEntry({
        "url": document.location.href,
        "title":document.title
    });

Any good advice whoever came across this situation?

like image 894
Vad Avatar asked Dec 04 '25 06:12

Vad


1 Answers

If you want to try this using AddThis, you can change the title and url by updating the page's title and history like this:

var title = "New Title"
window.document.title = title;
window.history.pushState({path: href}, title, href);

And then you just have to call:

addthis.toolbox('[selector for AddThis buttons]');

This will force all the share buttons to update themselves and use the new title/url specified. If you're still struggling with ShareThis, give this a try.

like image 129
Sol Avatar answered Dec 06 '25 23:12

Sol