cancel
Showing results for 
Search instead for 
Did you mean: 

close popup when parent window is closed

alberto_colonna
Participant
0 Kudos

Hi everybody,

I have written a bsp application with one page.

If the user clicks on a submitt-button a new window is opened by calling the

javascript function window.open.

Now I am looking for a way to close the sub-window automatically when the parent window is closed.

I have found the attribute "dependent" in the window.close function, but this only

works for netscape and nor internet explorer.

Could you help me

Best regards & Thanks a lot

Alberto

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Am sorry for confusing reply Here you can get it properly

1 ] Save this as parent.html

<!--<html>

//<script>

//var child;

// function poptesting(url){

// child=window.open(url,'Child',height=400,width=300);

// }

//</script>

//<body onUnload="if (child && !child.closed) child.close()">

//<h1>Hello</h1>

//<a href="javascript:poptesting('CHILD.html');"><h3>pop Up </h3></a>

//</body>

//</html> -->

2 ]Save this as child.html

<!--<html>

<body>

<h1>Thank You for Opening Me</h1>

<p><a href=" javascript:self.close();">Close</a></p>

</body>

</html> -->

it may help solving your question

Answers (4)

Answers (4)

alberto_colonna
Participant
0 Kudos

Hi Abhijith,

thanks you very much!!

Now it works.

Best regards

Alberto

Former Member
0 Kudos

<!-- <html>

//<body>

//<h1>Thank You for Opening Me</h1>

//<p><a href=" javascript:self.close();">Close</a></p>

//</body>

//</html> -->

Former Member
0 Kudos

Try out this :

1 ] Save this as parent.html

<html>

<script>

var child;

function poptesting(url){

child=window.open(url,'Child',height=400,width=300);

}

</script>

<body onUnload="if (child && !child.closed) child.close()">

<h1>Hello</h1>

<a href="javascript:poptesting('CHILD.html');"><h3>pop Up </h3></a>

</body>

</html>

2 ] Save this as child.html

<html>

<body>

<h1>Thank You for Opening Me</h1>

<p><a href=" javascript:self.close();">Close</a></p>

</body>

</html>

You can get some Idea with this

eddy_declercq
Active Contributor
0 Kudos

Hi,

Have a look at the dependant window part of

http://www.webreference.com/js/tutorial1/reference.html

Also have a look at

http://www.irt.org/script/98.htm

Eddy

-


PS. Reward useful answers and earn points yourself

alberto_colonna
Participant
0 Kudos

Hi Eddy,

I am using htmlb in my page, so the page doesn't include the body-tag.

Is it also possible to define the onUnload event without body-tag?

Best regards

Alberto

eddy_declercq
Active Contributor
0 Kudos

Hi,

Pls check this thread:

/thread/68952 [original link is broken]

Eddy

-


PS. Reward useful answers and earn points yourself

Former Member
0 Kudos

Hi Alberto,

you can add the onunload event to the body tag of the rendered html even in

htmlb. To do so you need the following:

Create a class that implements the interface if_bsp_bee

Add codinging similar to the following example to the if_bsp_bee~render_to_string method:

  result = 'onunload="callMyFunction();"'.

Instanciate the class and hand over the reference to this class to the attribute "attributeBee" of the htmlb-"documentBody" tag.

Be aware that the onunload is also triggered if you perform a submit on the page (at least it was the case the last time I tested that, maybe the browsers behaviour changed in the meantime).

Best Regards

Michael

alberto_colonna
Participant
0 Kudos

Hi,

I have only worked with ABAP for a few weeks.

do you have a code example, where I can see what you mean?

Best regards

Alberto

Former Member
0 Kudos

Hi Alberto,

here a example how to get the onunload into the body-tag by using htmlb. If you enrich this by the solutions proposed above (javascripts to close the dependent windows) it should solve your problems. My solution only shows the call of the javascript.

Call the Class Builder and create a class called e.g. zcl_bsp_body_bee. On the tab interfaces add an entry for if_bsp_bee.

Go to the method IF_BSP_BEE~RENDER_TO_STRING and add the coding so that the method implementation looks like:


METHOD if_bsp_bee~render_to_string.

  result = 'onunload="callMyFunction();"'.

ENDMETHOD.

Activate the class.

Go to your BSP-Page and create a page with flow logic (e.g. test_unload.htm). On the page attributes add a variable called gr_bee type ref to zcl_bsp_body_bee.

Add the following line in the OnRequest-Event of the page to instanciate the bee object:

CREATE OBJECT gr_bee.

Now go to the Layout and paste the following:

<%@page language="abap" otrTrim="TRUE"%>
<%@extension name="htmlb" prefix="htmlb"%>
<%@ extension name="phtmlb" prefix="phtmlb" %>
<%@ extension name="xhtmlb" prefix="xhtmlb" %>
<%@ extension name="bsp" prefix="bsp" %>
<htmlb:content design="design2003" controlRendering="SAP" forceEncode="ENABLED">
<htmlb:document>
<htmlb:documentHead title="Test OnUnload of Body Tag">
<%-- insert header includes here, e.g. for external references to javascript library if required --%>
<htmlb:headInclude />
<script language="JavaScript">
<%-- "Javascript-Function is called in the bee-object --%>
<!--
function callMyFunction()
{
alert("OnUnload was called!nClick OK to proceed");
}
//-->
</script>
</htmlb:documentHead>
<htmlb:documentBody attributeBee="<%=gr_bee%>" marginBottom="0" marginLeft="0" marginRight="0" marginTop="0" reposition="FALSE" scrolling="NO">
<htmlb:textView     text          = "Hello World!"
                           design        = "EMPHASIZED" />
</htmlb:documentBody>
</htmlb:document>
</htmlb:content>

Now if you activate and test this page you should get a popup once you close the browser or navigate away.

Dependent on when you want your child-popup getting closed you have to proceed here by either adding your form to this page (Onunload executed on every submit of the form) or by calling your "working page" in an iframe e.g.

  <iframe id="IframeRoot" src="<working_page>" style="margin:0px; height:100%; width:100%" scrolling="no">

This can also be used for automaticaly closing sessions of statefull applications in case the user navigates away/closes the browser. For this check out my posting in thread

Best Regards

Michael