cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript OnUnload

Former Member
0 Kudos

Hi experts,

i want to have an OnUnload event within my BSP

but I only know a OnLoad attribut in the <htmlb:documentBody>.

Is it possible to do a OnUnload?

For example: "Do you really want to leave this page?" -Yes-No Case (I'm familiar with the JS Part)

kind regards

Marcus

Accepted Solutions (1)

Accepted Solutions (1)

martin_schffler
Participant
0 Kudos

You can also use the attributeBee-attribute of the <htmlb:documentBody>-Tag. There you can insert any bee that contains additional attribute definitions for your body-tag.

The definition of the bee might look like that:


  DATA:                                                   
    lr_unloadbee TYPE REF TO cl_bsp_bee_table.            
                                                          
    CREATE OBJECT lr_unloadbee.                           
    lr_unloadbee->add_html( html = 'onUnload="doAnythingHere()"' ). 

But the questions you gave as an example is not that easy to implement, as the onUnload-event can't be canceled.

regards,

Martin

Message was edited by: Martin Schöffler

Former Member
0 Kudos

Hi Martin,

ok anything else to do with the reference lr_unloadbee?

Do i have to include it in my htmlb tag?

Why isnt it possible to cancel an OnUnload event?

martin_schffler
Participant
0 Kudos

Hi Marcus,

you have to add it to your <htmlb:documentBody>-tag.

Like this:


 <htmlb:documentBody attributeBee="<%=lr_unloadbee%>">

For the code to work you either have to make the definition of the bee in the view or you have to provide it to the view using a page attribute. In my case lr_unloadbee is the name of the page attribute.

The second question is a bit tougher. I don't know why it can't be canceled.

I usually use microsofts dhtml reference for any questions regarding html.

The page for the onUnload-Event: http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onunload.asp

If you work in an InternetExplorer-only environment you can use the onBeforeUnload-Event. This one can be canceled.

Former Member
0 Kudos

Hi everyone,

but in some cases (normal html) i used the window.close() JS function and a client submit like: "the window will close..." appeared. Is something like this possible?

Martin you are right: your script works but it executes the JS after! closing the window not before

Former Member
0 Kudos

Hi Martin,

this one works before the window close but it is not possible to cancel this event!?

JS Part:

function confirmClose()

{

var agree=confirm("Are you sure to close this window?");

if (agree)

return true ;

else

return false;

}

Former Member
0 Kudos

Hi,

the example on Microsoft showed me how to do the JS Part:

function confirmClose(htmlbevent)

{

event.returnValue = "This will close the application!";

}

Many thx

regards

Marcus

Former Member
0 Kudos

Sorry,

but now the onBeforeUnload event is responding with every refresh and button click on that site!

eddy_declercq
Active Contributor
0 Kudos

Hi,

We use this simple JS for warning people when the leave the app/popup without saving:

<script language="JavaScript">

var needToConfirm = false;

window.onbeforeunload = confirmExit;

function confirmExit()

{

if (needToConfirm)

return "Any change will be lost if you don't save when leaving the application.";

}

</script>

Eddy

Former Member
0 Kudos

Hi,

your script work like the one martin posted.

But how about setting the needtoconfirm var to true otherwise your script wont work!

But the same problem here:

The script executes whenever a button or link is clicked!

martin_schffler
Participant
0 Kudos

Hi,

you also need an enclosing frame that isn't reloaded on every request. Then you put the onUnload in that frame.

Former Member
0 Kudos

Hi,

sorry i dont know any enclosing frame,

can you give me an example?

Regards

Marcus

Former Member
0 Kudos

Hai Marcus,

http://www.4guysfromrolla.com/webtech/100604-1.shtml

this has a nice example which prompts the user to save the page when the user wants to leave the page with out saving.

Regards,

Venkatesh

Former Member
0 Kudos

Hi everyone,

now the problem is solved.

I did it with an iFrame on an normal html-site.

<htmlb:content design="design2003">

<htmlb:document>

<htmlb:documentHead>

<SIEHTMLB:textEditHeader/>

<script language="JavaScript">

var needToConfirm = true;

window.onbeforeunload = confirmExit;

function confirmExit()

{

if (needToConfirm)

return "This will close the application!";

}

</script>

</htmlb:documentHead>

<htmlb:documentBody>

<iframe src="main.do"

name="NameApplication" width="100%" height="100%" marginheight="0" marginwidth="0" align="center">

<p>Your Browser cannot show embedded Frames</p>

</iframe>

</htmlb:documentBody>

</htmlb:document>

</htmlb:content>

Thats all --- Thanks for every answer!

Regards,

Marcus

Message was edited by: Marcus Pohl

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Marcus,

You can just add on a HTML <body> tag. See the sample code below it will solve your issue.


<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<head>
<SCRIPT language="JavaScript">
function test()
{
  alert("Hi");
}
</SCRIPT>
</head>
<body onunload="test()">
<htmlb:content design="design2003" >
  <htmlb:page title="Java script onunload test " >
    <htmlb:form>
      <htmlb:textView text   = "Hello World!"
                      design = "EMPHASIZED" />
      <htmlb:button text    = "Press Me"
                    onClick = "myClickHandler" />
    </htmlb:form>
  </htmlb:page>
</htmlb:content>
</body>

Hope this helps,

Regards,

Ravikiran.

Former Member
0 Kudos

hi,

check the sample bsp application:

HTMLB_samples

look at:logoff.htm

its a good sample you can use it and modify it.

Regards,

Hemendra