Load LinkedIn member profile by inserting javascript with Jquery

半世苍凉 提交于 2019-12-08 10:37:56

问题


I am trying to display LinkedIn member profiles by having a user enter in their public profile URL then loading that profile using JQuery. When they enter in www.linked.in/com/in/theirprofile, I am calling this:

$(document).ready( function(){
    $("#linkedin_field").blur( function(){
        $("#profile").html('<script type="IN/MemberProfile" data-id="' + $("#linkedin_field").val() + '" data-format="inline"><\/script>')
    });
});

This does insert the javascript into the #profile div but it doesn't display the member's profile. How can I get the profile to load when I insert the new javascript?

Note that this page is successfully loading the profile when I include the javascript at the beginning with a valid user profile.


回答1:


It takes one line for LinkedIn to parse the rendered javascript, so all that's necessary is:

$(document).ready( function(){
    $("#linkedin_field").blur( function(){
        $("#profile").html('<script type="IN/MemberProfile" data-id="' + $("#linkedin_field").val() + '" data-format="inline"><\/script>')
    });
    IN.parse(document.getElementById("profile"))
});



回答2:


I'm going to guess that "IN/MemberProfile" is for a JavaScript-based widget provided by LinkedIn, as I don't see any other way you could expect that code to work.

If that's the case, the LinkedIn widget likely only runs on the first page load. Thus, injecting a script tag still isn't going to get the LinkedIn JavaScript to re-execute.

If you inject the LinkedIn JavaScript file after the widget code it will likely re-execute, or you could attempt to find the function in the LinkedIn JavaScript that renders their widgets and re-call it.



来源:https://stackoverflow.com/questions/6866912/load-linkedin-member-profile-by-inserting-javascript-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!