簡體   English   中英

如何調用LinkedIn從按鈕授權javascript

[英]How to call LinkedIn authorize javascript from button

這行來自LinkedIn API的示例代碼非常有效。

<script type="IN/Login" data-onAuth="loadData"></script>

但它會在網頁加載時自動運行。 我想使用網頁上的按鈕或鏈接來調用此腳本。 該想法是網頁加載並等待用戶准備進行身份驗證。

理想情況下,我希望LinkedIn登錄圖像出現並等待,直到單擊為止。

謝謝。

根據您的評論,您似乎只想在用戶手動單擊頁面上的按鈕/元素時顯示SignIn插件 這樣的事情,使用jQuery ,應該可以工作:

在頁面上,您有一個按鈕:

<div id="buttonControl">
  <input type="button" id="showLinkedIn" value="Show LinkedIn" onclick="showLinkedIn();" />
</div>
<div id="buttonContent" style="display: none;"></div>

在頁面<head>的腳本塊中,您具有showLinkedIn() onclick函數:

function showLinkedIn() {
  // insert the SignIn plugin
  $('#buttonContent').html('<script type="IN/Login" data-onauth="loadData"><\/script>');

  // tell the LinkedIn JavaScript code to re-parse the element containing the SignIn plugin
  IN.parse($('#buttonContent')[0]);

  // hide button trigger, if needed
  $('#buttonControl').hide();

  // show the LinkedIn control
  $('#buttonContent').show();
}
$('#buttonControl').click(function(){
    $('#buttonContent').html('<script type="IN/Login" data-onauth="loadData"></script>');
    $('#buttonControl,#buttonContent').toggle();
    IN.User.authorize(loadData);
    });

與'IN.parse($('#buttonContent')[0]);'稍有不同 似乎不起作用...

測試了“ IN.User.authorize(loadData)”,效果很好! 從以下位置獲得它: http : //developer.linkedin.com/documents/inauth-inevent-and-inui

您需要通過以下方法清除Cookie,例如

IN.User.logout(callbackFunction, callbackScope);

您需要在要注銷的按鈕上調用此函數。

使用jquery的示例:

$('#demo') .click(function() 
{
    IN.User.logout(console.log("logged out..."));
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM