javascript - Close Twitter Oauth login popup and redirect with callback to parent -


i'm implementing twitter oauth java in website , have problem login popup.

i open authorization url in popup window , when user finish login proccess, twitter redirects callback url in popup. need know, if possible close popup , redirects callback url in parent page.

finally found solution. posted in twitter developer forums well. did:

i set timer function running every second. in function check popup url, while i'm out of domain can't when callback url launched, window come domain read de url , if can find oauth_verifier field in url close popup , read url recover verifier.

function logintwitter(){     var f = document.forms["mainform"];        var url = "https://api.twitter.com/oauth/authorize?oauth_token=***********";     var mywindow = window.open(url,"","resizable=yes,width=600,height=400,toolbar=no,titlebar=no,menubar=no,scrollbars=yes");     var timer = setinterval(checkwindow, 1000);       function checkwindow() {       try {          var ur = mywindow.location.href;            if (ur.indexof('oauth_verifier') != -1){               var verifier = "";               var token = "";               clearinterval(timer);               mywindow.close();               ur = ur.substring(ur.indexof('?')+1);               var urpartes = ur.split('&');               (i = 0; < urpartes.length; i++){                  if (urpartes[i].indexof('oauth_verifier') != -1){                    verifier = urpartes[i].split('=')[1];                 }                  if (urpartes[i].indexof('oauth_token') != -1){                         token = urpartes[i].split('=')[1];                 }              }               f.oauth_verifier.value = verifier;               f.oauth_token.value = token;               //here ajax call done params in form final verification against twitter nthe server           }       } catch (e){       } //end catch        }//end function checkwindow }//end function logintwitter 

the try/catch block avoid js errors "mywindow.location.href" while i'm trying access url while popup out of domain. know not way couldn't find useful.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -