Nayan Jain
Nayan Jain

Reputation: 178

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

Upvotes: 2

Views: 1710

Answers (3)

Jeffery To
Jeffery To

Reputation: 11936

I'm guessing you are trying to dynamically add a LinkedIn script tag (with a dynamic data-id) on page ready/unload or after. LinkedIn's library will scan the page for script tags to parse on page ready so it may not see your dynamic tag in time.

According to http://developer.linkedin.com/docs/DOC-1292#Parsing_Tags you can call IN.parse(domNode) to render any dynamically added LinkedIn tags. So after your example code you can do:

IN.parse($("#search-results")[0]);

Upvotes: 1

rivenate247
rivenate247

Reputation: 2101

resultsHtml += '<script type="IN/MemberProfile" data-id="'+currResult.publicProfileUrl+'" data-format="inline"/>';

one thing you're missing from the example is the closing </script>

resultsHtml += '<script type="IN/MemberProfile" data-id="'+currResult.publicProfileUrl+'" data-format="inline"></script>';

so it can look like their example of:

<script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/MemberProfile" data-id="/in/jeffweiner08" data-format="inline"></script>

Upvotes: 0

Naftali
Naftali

Reputation: 146310

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);
   ...

})

Upvotes: 1

Related Questions