-1

My scenario is something like this. Technology used for UI side is SmartGwt. In my application, Onclick of a button, opens a popup window, then pop up window is loaded with html contents from cross-domain url. I do not have popup window reference inside the html code present in pop window.

I have got close button inside the html of popup window. Onclick of a close button, window should get closed.

Currently its not happening. I tried with window.close() methods and also with window.postmessage implementation. Nothing got worked.

How do I close the popup window when window is not opened by the script?

Any ideas?

099
  • 333
  • 1
  • 15
yogish
  • 85
  • 17
  • have you tried to bind `window.open('','_self').close();` to on your close button `onclick`? – sander Aug 20 '15 at 08:22
  • @ebilgin Thats correct – yogish Aug 20 '15 at 08:50
  • @sander I tried with that.. Here I am opening pop up window through my application. and contents in pop up window are from other domain, which I have got no control. When I tried to access pop window using window. parent, I am getting this exception "Blocked a frame with origin..........." – yogish Aug 20 '15 at 08:53

2 Answers2

0

use this code in parent page.

 /*For closing the popups from inside close button*/
    closeDialog = function () {
        $("#dialog").dialog("close");
    }

use this code in child page.

   jQuery(function () {

        jQuery("#btnClose").click(function () {
            parent.closePopup();
        });
    });
0

I'm not really familiar with SmartGwt, and as soon as you provide no code or html examples, my suggestions would be more general.

So your code should look like either:

    ...
    var popUp=window.open(/*arguments*/); // open the window
    ...
    popUp.close(); // close the window

Or you could just wrap an iframe with some div to create pseudo-popup-window (and "open"/"close" it by manipulating iframe's src and wrapping div's visibility) instead of opening/closing actual windows.

sander
  • 388
  • 1
  • 3
  • 10