Initiate Google sign in on button click

Hello I am using google api to sign in to my web application . Now Its working fine . But the problem is the sigin is initiated automatically as I go to my log in page . But I do not want that . I want the user to click the signin button first then the process will start .

I am using below button

<div class="g-signin2" data-onsuccess="onSignIn"></div>

and google log in references .



Use 'attachClickHandler' to Initiate Google Sign In.

<script src="" async defer></script>
   function init() {
        gapi.load('auth2', function() {
            auth2 = gapi.auth2.init({
                client_id: '*************',
                cookiepolicy: 'single_host_origin',
                scope: 'profile email'
            element = document.getElementById('glogin');
            auth2.attachClickHandler(element, {}, onSignUp, onFailure);
    function onSignUp(googleUser) {
      var profile = googleUser.getBasicProfile();

Best way is to use Java Script to sign in to google as I have found out .


script type="text/javascript">
      (function() {
       var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
       po.src = '';
       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);

to initialize js . And finally call below method to sign-in user

function login() 
  var myParams = {
    'clientid' : '', //You need to set client id
    'cookiepolicy' : 'single_host_origin',
    'callback' : 'loginCallback', //callback function
    'scope' : ''

By using this I was able to solve this problem . Now User needs to click on sign-in to login


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.