Page 1 of 2

how to handle page leave event

Posted: Mon Sep 23, 2013 1:42 am
by rammohan.acharyadasa

Hi
i have i am creating mobile app which will work on ios,android.
when the users clicks navigates to another page, example from pageA to PageB.
i want to handle page left event fo "PageA" to stop palying the html5 audio.
how i can handle page left event on "PageA"


how to handle page leave event

Posted: Mon Sep 23, 2013 2:14 am
by Alena Prykhodko

Hi!

Not sure I understand you correctly. Do you mean on page A you play audio then after click on this page it stops playing and navigate to page B?


how to handle page leave event

Posted: Mon Sep 23, 2013 2:25 am
by rammohan.acharyadasa

i have html5 audio player on PageA.
it works great.
the user clicks play icon of the html5 audi it plays music. it is working fine. no issues
there is backbutton on pageA, when the user clicks on the "backbutton" or cliks anythin on the tab (bottom line have 5 tabs to go to other pages etc..) to go to another pages of the App.
i want to sop the audio when the pageA is navgated to any other page. ( the user may click either "Bakbutton" or any one of the tab (bottom i have 5 tabs)
how to achieve this
i am thinking to handle page left( if any such event exists) event of "PageA" , i want to write below code:
$("#myHtml5audio1").pause();
$("#myHtml5audio1").currentTime = 0;
but i am not finding "page left" event to hadle.
how to handle page left evet( or any other event similar to page left so that i can stop palying the audio when the user moves out from the pageA)


how to handle page leave event

Posted: Mon Sep 23, 2013 3:45 am
by maxkatz

Just before you navigate, run JavaScript to stop playing the audio.


how to handle page leave event

Posted: Mon Sep 23, 2013 3:51 am
by rammohan.acharyadasa

which event i need to handle
i know i need to choose "action" as "run javascript"
but for the PageA, which event i need to choose. i tried "unload" it is not firing.
i also tried "page hide" event but it is also not firing.


how to handle page leave event

Posted: Mon Sep 23, 2013 3:54 am
by maxkatz

Run the JavaScript just before you invoke navigation.


how to handle page leave event

Posted: Tue Feb 25, 2014 12:49 am
by Victor Fagerström

That means it has to be done manually to every navigation button that leaves the page. Is there a way, such as an event like "beforeleavingpage run javascript", to achieve this with clicking any navigation button that leaves the page?

V


how to handle page leave event

Posted: Tue Feb 25, 2014 12:51 am
by Victor Fagerström

run javascript on page hide seems to be working for me now, is that the right way to do it?

V


how to handle page leave event

Posted: Tue Feb 25, 2014 1:04 pm
by Maryna Brodina

Hello!
If Run JS action on page Hide event works the way you need, you can use it.


how to handle page leave event

Posted: Tue Feb 25, 2014 4:52 pm
by Victor Fagerström

Would it be possible to run the JS action BEFORE the navigation away from page happens?
At page Hide event JS action seems to run after navigation is complete or has at least started.

V