开发者

How can I make the Share This button to share the link it stays beside?

开发者 https://www.devze.com 2023-03-12 02:19 出处:网络
so is this Share This button which is doing a pretty good job except the fact that is not sharing the link is staying beside but the link of the page is staying on.

so is this Share This button which is doing a pretty good job except the fact that is not sharing the link is staying beside but the link of the page is staying on.

e.g. StackOverflow LinkSHARE THIS button.

question: how can I开发者_如何转开发 make this button to share the link it stays beside, in this case, to share the StackOverflow Link?

I'm pretty much a newbie in JS so if someone can share the entire working code here will be appreciated :)

Thanks folks :) VD


Assuming your link is an anchor (<a... />) and your button is a button (<input type="button" />) you can wrap them both in a container and do something like this:

<div>
  <a href="http://www.stackoverflow.com/">link</a>  
  <input type="button" value="share link" />
</div>

$(document).ready(function() {
  $('input:button').click(function() {
    var url = $(this).parent().find('a').attr('href');
    // do something to share url.
  });
});

Example: http://jsfiddle.net/fallen888/PaJLT/2/

0

精彩评论

暂无评论...
验证码 换一张
取 消