sscirrus
sscirrus

Reputation: 56719

Load LinkedIn member profile by inserting javascript with Jquery

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.

Upvotes: 0

Views: 2287

Answers (2)

sscirrus
sscirrus

Reputation: 56719

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"))
});

Upvotes: 2

ceejayoz
ceejayoz

Reputation: 180004

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.

Upvotes: 0

Related Questions