1

I have a piece of code to log user out from linkedin and its not working :(

any help will be greatly appreciated.


Logout code


<html>
<head>
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
  api_key: mykey
  authorize: true
</script>
<script type="text/javascript">

try {
    IN.User.logout();
} catch (err) {
    console.log(err);
}
setTimeout("goToHome()", 10000);

function goToHome() {
    location.href="index.php";
}
</script>
</head>
</html>

console log


TypeError
arguments: Array[2]
get message: function () { [native code] }
get stack: function () { [native code] }
set message: function () { [native code] }
set stack: function () { [native code] }
type: "non_object_property_call"
__proto__: Error

Best regards, Pawan

Pawan
  • 517
  • 1
  • 9
  • 25

1 Answers1

3

It looks like you are trying to call IN.User.logout() before the LinkedIn JavaScript platform has completely loaded. You should run the code only once you are sure the library is loaded, via either the onLoad value in the platform bootstrap section:

<script type="text/javascript" src="http://platform.linkedin.com/in.js">
  api_key: mykey
  authorize: true
  onLoad: onLoad
</script>

<script type="text/javascript">
function onLoad() {
  try {
    IN.User.logout();
  } catch (err) {
    console.log(err);
  }
  setTimeout("goToHome()", 10000);
}

function goToHome() {
  location.href="index.php";
}
</script>

Alternatively, use one of the event callbacks:

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

<script type="text/javascript">
IN.Event.onOnce(IN, 'systemReady', function() {
  try {
    IN.User.logout();
  } catch (err) {
    console.log(err);
  }
  setTimeout("goToHome()", 10000);
});

function goToHome() {
  location.href="index.php";
}
</script>
Bart
  • 19,692
  • 7
  • 68
  • 77
Unpossible
  • 10,607
  • 22
  • 75
  • 113
  • thanks mate... i have updated all my acceptance status and now its 90% :)... cheers – Pawan Sep 20 '12 at 01:11
  • i tried both solutions and then included jquery to use $(window).load(); and $(document).ready() too but nothing works for me :( – Pawan Sep 20 '12 at 01:12
  • now it says ==> Unsafe JavaScript attempt to access frame with URL http://mysite.com/logout.php from frame with URL https://platform.linkedin.com/js/xdrpc.html?v=0.0.2000-RC1.21420-1402#xdm_e=http%3A%2F%2Fbeta.mytechlogy.com&xdm_c=li_gen_1348103554579_0&xdm_p=1&target=li_gen_1348103554579_0&width=600&height=400&mode=wrapper. Domains, protocols and ports must match. xdrpc.html:1300 getXDClosure xdrpc.html:1300 (anonymous function) xdrpc.html:1303 (anonymous function) xdrpc.html:1557 – Pawan Sep 20 '12 at 01:14
  • I've tried the code and it seems to work - the error you are seeing is common to the LinkedIn JavaScript platform. – Unpossible Sep 20 '12 at 14:32