Search code examples
javascripthtmllinkedin-api

LinkedIn API: Dynamic UI Component


I am trying to dynamically populate the data-id field with a public url fetched from linkedin search results. Assume that I am able to return the public profile url. If I put the same script directly on the page (not through javascript) it works.

resultsHtml += '<script type="IN/MemberProfile" data-id="'+currResult.publicProfileUrl+'" data-format="inline"/>'; 
$("#search-results").html(resultsHtml);

For reference

http://developer.linkedin.com/docs/DOC-1278


Solution

  • if you are using jQuery which i am assuming you are, you 1st need to run that 1st js file: http://platform.linkedin.com/in.js

    so make sure you have:

    <script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
    

    in the head of the doc.

    and then in the body when u call it:

    $(function(){
    
       ...
       //here is the hack:
       resultsHtml += '<sc'+'ript type="IN/MemberProfile" data-id="'+currResult.publicProfileUrl+'" data-format="inline"></sc'+'ript>';
       //remember to close script tags 
    
       $("#search-results").html(resultsHtml);
    
       ...
    
    })
    

    or you can try this:

    $(function(){
    
       ...
    
       var $script = $('<script>',{
                        'data-format': 'inline',
                        type: 'IN/MemberProfile',
                        'data-id': "'+currResult.publicProfileUrl+'"
                      })
    
       $("#search-results").html(resultsHtml);
       $("#search-results").append($script);
       ...
    
    })