javascript - Open and Close a Simple Popup Window in Chrome Extension -


i have chrome extension should allow users log in google via popup because won't display in iframe. doing window.open() worked fine except not close pop-up after user logged in.

i have been trying no success use chrome.windows.create instead of window.open in hopes able close popup once detect via url have logged in.

in popup_google.js have simple function:

function login(login_url) {     // var win = window.open(login_url, "windowname1", 'width=800, height=600');     chrome.windows.create({'url': 'http://stackoverflow.com/', 'type': 'popup'}, function(window) { }); } 

the login function called via "onclick" this:

<a href='#' onclick='login("https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=http%3a%2f%2fdev.sbceoportal.org%2fcastest%2fwp-login.php&client_id=191567976061-9uksb59gedrtlsmoeo1fouov94370j96.apps.googleusercontent.com&scope=openid+email+https%3a%2f%2fwww.googleapis.com%2fauth%2fuserinfo.profile&access_type=online&approval_prompt=auto&state=d96bdddc11%257chttp%253a%252f%252fdev.sbceoportal.org%252fcastest%252fportal%252f");' id="logintext"> click here login </a> 

i can't life of me chrome.windows.create open new popup window, in simplest form see here, window.open works charm (i can't seem closed in chrome).

it looks popup_google.js file content script. content scripts cannot use chrome.*apis except few exceptions. why can't use chrome.window api @ all. on similar note, adding "tabs" permissions utilizes chrome.tabs api not 1 of few allowed chrome apis content scripts. try using matches: [/url pattern/] field limit urls in content script run, shown in content script api.

content scripts have full access dom not variables or functions defined web pages. while can create own popup using window.open, content script has no way sure referencing correct 'window' variable when wish call window.close() because script sees 2 windows: 1 created using window.open() , window loaded on page's dom.

try looking @ chrome's examples using popups , modify them achieve desired functionality. or check out other great explanations develop working popup login.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -