jQuery目标LinkedIn分享按钮

时间:2014-12-08 22:35:58

标签: jquery linkedin jquery-events

我有一个LinkedIn分享按钮,我需要使用jQuery来保存共享的内容等。我已经对Twitter做了同样的事情,Twitter有一个api用于捕获事件,但我有LinkedIn的一个问题。由于它不是iframe,我想我可以捕捉事件。这是初始代码:

<li id="linkedin-share">
    <script src="//platform.linkedin.com/in.js" type="text/javascript">
        lang: en_US
    </script>
    <script type="IN/Share"></script>
</li>

因此,共享工作正常,但我无法捕获点击。我已设法在Chrome DevTool的控制台中捕获渲染的html元素,但我没有设法捕获点击。我尝试过这样的事情:

$('<fixed parent>').on('click', '<rendered content catchable in devtools>', function(){
    console.log('captured');
});

任何想法,是否有一些预定义的方法来做到这一点?

2 个答案:

答案 0 :(得分:0)

<script type="IN/Share" data-onSuccess="shared"></script>

function shared(){
     console.log('shared');
}

hacky解决方案

jQuery('#tester').click(function(){

    //share function here!
    IN.UI.Share().params({
    url: "http://www.example.com"
    }).place()
});

链接到文档:https://developer.linkedin.com/documents/inauth-inevent-and-inui很遗憾没有成功分享的事件。

答案 1 :(得分:0)

如果您只是在LinkedIn上进行共享,那么为什么要依靠他们的API进行共享?您应该可以通过简单的直接链接来做到这一点:

<a id="share-on-linkedin" href="https://www.linkedin.com/sharing/share-offsite/?url=http%3A%2F%2Frevoltlib.com%2F">Share On LinkedIn</a>

然后,您将可以像其他任何元素一样直接控制该元素:

$('#share-on-linkedin').click(function(e) {});

来源: Official Microsoft Linkedin Share Plugin Documentation