javascript - 领英回调函数
问题描述
我想在单击链接的共享按钮后调用一个函数。
<div class="linkedinShare ci-aling" linkedin data-url='{{url}}' data-title='{{title}}' data-summary="{{text}}" data-shares='linkedinshares'>{{linkedinshares}}</div>
这是我试图调用的脚本,但它只在页面加载时被调用,并且在单击链接中的共享按钮时不会被调用。我希望在单击共享按钮时调用我的功能。
$.getScript('http://platform.linkedin.com/in.js', function () {
debugger
IN.Event.on(IN, 'systemReady', handleLinkedInEvent);
function handleLinkedInEvent(event) {
debugger
if (event) {
EventService.UpdateEventAudit($scope.event_id, "LinkedIn",
GetUrlReferrer());
}
}
});
UpdateEventAudit 是我试图调用的函数。有人知道吗?
解决方案
如果我正确理解这一点,您希望能够在用户通过linkedin 共享时跟踪事件...
我确实尝试了你的代码,经过一些研发,找到了另一种调用 api 的方法......
创建了一个迷你笔,您可以在此处查看https://codepen.io/craigiswayne/pen/Bqqbjz
可以在此处找到有关此主题的文档:https ://developer.linkedin.com/docs/share-on-linkedin
IN.Event.on(IN, 'systemReady', function() {
var shareLink = document.getElementById('shareLink');
shareLink.onclick = function(){
event.preventDefault();
var params = {
"comment": "Check out developer.linkedin.com! " + this.getAttribute('href'),
"visibility": {
"code": "anyone"
}
};
IN.API.Raw("/people/~/shares?format=json")
.method("POST")
.body(JSON.stringify(params))
.result(StackOverflowDemo.updateShareCount)
.error(function(errorMessage){
StackOverflowDemo.logOutput('error occurred');
console.log(errorMessage);
});
};
document.body.appendChild(shareLink);
});
var StackOverflowDemo = {
updateShareCount: function(result){
var existingCount = parseInt( document.getElementById('count').value );
existingCount = isNaN(existingCount) ? 0 : existingCount;
document.getElementById('count').value = existingCount + 1;
StackOverflowDemo.logOutput( 'updated count' );
StackOverflowDemo.logOutput( 'Total Shares = ' + document.getElementById('count').value );
StackOverflowDemo.logOutput( 'View Share here ' + result.updateUrl );
},
logOutput: function(text){
document.getElementById('output').value += text + '\n';
}
}
推荐阅读
- sql - 使用正则表达式将多个值从列转换为行
- github - 有没有办法在Jmeter和Github之间集成来推送jmx文件
- python-3.x - 如何让 Dramatiq 在 Windows / WSL 环境中使用 redis?
- java - 如何通过单击 HBox 而不是按钮来切换 SceneBuilder
- ansible - 如何在给定时间内启动ansible脚本
- c++ - 如何调试我的 C++ 二叉搜索树?
- javascript - Javascript 如何从 URL 中将 ID 提取为 INT?
- arrays - 从 Julia 中的字母表中有效地生成长度为 n 的所有单词的集合
- sdk - 腾讯 Bugly SDK
- javascript - 如何使用谷歌图表在条形图顶部插入点?