how to call a function on closing the page

UI Components for JSF
Post Reply
User avatar
zorro6064
Posts: 59
Joined: 01 Mar 2011, 16:20

22 Oct 2011, 10:49

When a user closes the window or tab of my web application, I need to call a function.
How can I do it?
I used

Code: Select all

 <script type="text/javascript">
            window.onbeforeunload = function()
            {
                exitFunc();
                alert("test 1");
            }
            
        </script>
and

Code: Select all

 <h:form id="exitForm">
                <p:remoteCommand name="exitFunc" actionListener="#{testBen.outFunc}" />
 </h:form>
but by clicking on any item of my menu(p:menu) this method called.
can any body guide me?

User avatar
zorro6064
Posts: 59
Joined: 01 Mar 2011, 16:20

24 Oct 2011, 10:01

any body have an idea to help me?

eumagnun
Posts: 1
Joined: 19 Sep 2012, 23:30

19 Sep 2012, 23:43

Hi!
I was resolved this with it:

Code: Select all

<body onunload="test();">	
   <form id="exit">
        <p:remoteCommand  id="test" name="test" action="#{ContatoMB.teste}"/>
  </form>
</body>

wolf97084
Posts: 15
Joined: 23 Mar 2015, 17:03

24 Jun 2016, 17:13

@eumagnun Thank you. It solved my problem. :)
PrimeFaces 7.0; JSF 2.2, Tomcat 9.0

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 38 guests