kytta / shareon

📯 Lightweight, stylish, and ethical share buttons for popular social networks
https://shareon.js.org/
MIT License
465 stars 25 forks source link

Dynamic url not working #38

Closed deepakkashyap3013 closed 3 years ago

deepakkashyap3013 commented 3 years ago

Whenever I am passing a URL with dynamic endpoints it is taking the current page url . How to use dynamic urls in the data-url attribute ?

kytta commented 3 years ago

Hi, can you clarify what you mean by dynamic endpoints?

deepakkashyap3013 commented 3 years ago

For eg : data-url="https://dapplooker.com/integration/" this is working fine but if i add a variable end point like data-url="https://dapplooker.com/integration/{{variable}}" in this case the url shown in the twitter is the current page url not the intended one

kytta commented 3 years ago

if i add a variable end point like data-url="https://dapplooker.com/integration/{{variable}}"

Do you use some sort of framework? shareon is not optimized for such use, yet supports it.

shareon only updates the buttons once. After the page is loaded, it searches for all .shareon containers and updates the href (or onclick) parameters. If the data-attributes are then changed, shareon doesn't see it. To manually update it, you need to call the shareon() function. It is exported when you import "shareon" or, if you use the browser link, is available as window.shareon(). See first code snippet in Initialization for reference.

In your case, I believe you need to add some sort of hook to update the URLs via shareon() each time the variable changes value

deepakkashyap3013 commented 3 years ago

Thanks for sharing this :)