http - Why does Chrome auto-close links to my site with target of a new window? -
i'm stumped on this, if can offer clue, i'd appreciate it.
here's site (built in rails): http://floating-autumn-3174.herokuapp.com/
when attempts visit site link on facebook or twitter, new tab loaded closes right away. happens in chrome. works fine in firefox.
if right click on link , select "open in new tab" loads fine.
if right click , copy link, works fine.
i thought might ssl redirects, tested staging environment (no ssl) , works fine.
so auto-closing happens in chrome , when clicking on link loads new tab.
any clue what's going on or how can better troubleshoot this?
edit
ok, after looking our included javascripts more believe i've found issue. involves js use handle pop-ups. first let me explain we're trying do. authenticate via facebook. when user click "sign in via facebook" pop launches , authenticates. when successful popup closes , main window refreshes in signed in state. works fine realize popup closing code killing other new windows. here' full code snippet below:
function popupcenter(url, width, height, name) { var left = (screen.width/2)-(width/2); var top = (screen.height/2)-(height/2); return window.open(url, name, "menubar=no,toolbar=no,status=no,width="+width+",height="+height+",toolbar=no,left="+left+",top="+top); } $(document).ready(function(){ $("a.popup").click(function(e) { popupcenter($(this).attr("href"), $(this).attr("data-width"), $(this).attr("data-height"), "authpopup"); e.stoppropagation(); return false; }); if(window.opener) { window.opener.location.reload(true); window.close() } });
the last if statement believe causing problem. i'm serious js noob i'm not sure how go fixing this. want last condition fire if link popup. how go doing that? again help.
edit 2
i went ahead rob's answer below , thought working hit 1 edge case i'm hoping with. apparently when user goes through facebook authentication first time window.name no longer "authpopup". think thats because popup goes through multiple steps , ends screen asking permissions. in scenario popup not close. on subsequent login popup closes doesn't need go through steps , "authpopup" condition remains true. how able handle this?
edit 3
i've arrived @ solution believe works. first looked window name of facebook auth screen per rob's suggestion found changes each time , not predictable. instead decided go global variable route. here's final code i'm using in case others find useful.
function popupcenter(url, width, height, name) { var left = (screen.width/2)-(width/2); var top = (screen.height/2)-(height/2); popupvalue = "on"; return window.open(url, name, "menubar=no,toolbar=no,status=no,width="+width+",height="+height+",toolbar=no,left="+left+",top="+top ); } $(document).ready(function(){ $("a.popup").click(function(e) { popupcenter($(this).attr("href"), $(this).attr("data-width"), $(this).attr("data-height"), "authpopup"); e.stoppropagation(); return false; }); if(window.opener && window.opener.popupvalue === 'on') { delete window.opener.popupvalue; window.opener.location.reload(true); window.close() } });
simply check value of window.name
property:
if (window.opener && window.name === 'authpopup') { window.opener.location.reload(); window.close(); }
additionally, can validate url of opener, other websites not refreshed when open site in window called "authpopup". since pages @ same domain, can set variable in original window, page not refresh when user navigates away, page.
Comments
Post a Comment