このJavaScript関数は、ブラウザのブロックを避け、認証のためにコールバックを使用して、人気のソーシャルネットワークのアプローチを模倣するOAUTHポップアップウィンドウを作成します。
demo
// OAuth popup window function $.oauthpopup = function(options) { // Set default options options.windowName = options.windowName || 'ConnectWithOAuth'; // Avoid spaces for IE compatibility options.windowOptions = options.windowOptions || 'location=0,status=0,width=800,height=400'; options.callback = options.callback || function() { window.location.reload(); }; var that = this; console.log(options.path); // Use console.log for better debugging // Open the OAuth window that._oauthWindow = window.open(options.path, options.windowName, options.windowOptions); // Monitor the window closure that._oauthInterval = window.setInterval(function() { if (that._oauthWindow.closed) { window.clearInterval(that._oauthInterval); options.callback(); } }, 1000); };
// Create and monitor the OAuth popup $.oauthpopup({ path: urltoopen, callback: function() { console.log('callback'); // Use console.log for better debugging // Perform callback actions here } });
以上がJavaScript OAuthポップアップウィンドウハンドラーコードの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。