1

I want to sign out from my website after login using google plus this is my script for signout

function signOut() {
    var auth2 = gapi.auth2.getAuthInstance();
    auth2.signOut().then(function () {
        console.log('User signed out.');           
    });
}

this is signout button

<li id="google_plus" style=""><a href="#" onclick="signOut()">Logouts</a></li>

but when i try to sign out this error will show

Uncaught ReferenceError: signOut is not defined at HTMLAnchorElement.onclick (VM684 home:269)

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
dipti
  • 154
  • 6
  • 17
  • you may like this post https://stackoverflow.com/questions/17378199/uncaught-referenceerror-function-is-not-defined-with-onclick/17378538?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Lokesh Pandey May 14 '18 at 11:47

1 Answers1

1

The error you're getting is telling you that your signOut() function can't be found.

Try reformatting your code, as follows, and remove onclick="signOut()" from your HTML - it should stop that error from showing.

I notice you've tagged the question with jQuery - so I assume you're using it. You could try this:

$('#google_plus_a').on('click', function(e) {
  e.preventDefault();
  var auth2 = gapi.auth2.getAuthInstance();
    auth2.signOut().then(function () {
        console.log('User signed out.');
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<li id="google_plus" style=""><a href="#" id="google_plus_a">Logouts</a></li>
Alex Mulchinock
  • 2,119
  • 1
  • 18
  • 25
  • The error you're getting is telling you that your ```signOut()``` function can't be found. If you use the code example I have given in your code, and remove ```onclick="signOut()"``` from your HTML - it should stop that error from showing. – Alex Mulchinock May 14 '18 at 12:04
  • yes i remove onclick="signout()" from html ,but nothing happen console message not show.if i remove signout() then what to write in line auth2.signOut().then(function () in place of signOut(). – dipti May 14 '18 at 12:23
  • Have you refactored your code, so it looks as mine does in the example above? – Alex Mulchinock May 14 '18 at 12:24
  • Sounds like jQuery isn't targeting your element. See my updated example (HTML and Javascript). – Alex Mulchinock May 14 '18 at 12:29