0

Is there a way to detect if the current user agent support popup using native javascript?

for example in WEB, window.open will open a popup, and the parent will know when the popup is closed.

however in Iphone for example or Ipad it opens the popup in new tab and the parents will lose the context. so the parent's can't listen to the event when the new tab is closed.

Currently am using a work around, is by checking each device manually if it's supports popup and then in my javascript i check the user agent if it's included in the list i checked manually. but i was thinking if there are more intelligent way to implement this.

Thanks.

Wagdi
  • 119
  • 6

2 Answers2

1

you can try this script:

<Script>
var windowName = 'userConsole'; 
var popUp = window.open('/popup-page.php', windowName, 'width=1000, height=700, left=24, top=24, scrollbars, resizable');
if (popUp == null || typeof(popUp)=='undefined') {  
    alert('Please disable your pop-up blocker and click the "Open" link again.'); 
} 
else {  
    popUp.focus();// this will open popup if the browser allow it.you can do your implementation on popup support here
}
</script>

main source:here

Suchit kumar
  • 11,809
  • 3
  • 22
  • 44
  • With this approach it will detect if the browser blocking the popup or not. What i am looking for is if the current device(web, iphone, android,ipad) is supporting popop. for example if i am using chrome in web and the popup is not blocked, and i call window.open it will open a popup. however in Iphone, if i use window.open it will open new tab and not popup. so what i am looking for is whether the current user agent(iphone, android,ipad,web) is supporting popup or it will open new tab instead of popup. – Wagdi Dec 16 '14 at 15:57
0

What are you trying to accomplish, exactly? Are you trying to detect if the current window is a popup? If so, BornToCode's response in this thread might be your answer. He suggests to test if window.opener is defined:

if ( window.opener !== 'undefined' ) 
Community
  • 1
  • 1
Marventus
  • 864
  • 1
  • 7
  • 14
  • What i am trying to accomplish is, if the user agent(iphone, web, android,...) supporting popup, then i will call function A. if it's not supporting pop e.g iphone, to call function B. – Wagdi Dec 16 '14 at 16:01
  • I understand. I think testing for that is kind of a catch 22, so I don't know how you could accomplish this natively. That being said, I know you were trying to accomplish this with native JS only, but have you considered using jQuery + jQuery UI Dialog? That way, your script would be able to respond in the same manner for all user agents and bypass the popup test altogether. – Marventus Dec 16 '14 at 18:50
  • Thanks for the response, however native JS is a requirement for this implementation – Wagdi Dec 16 '14 at 19:36