framework7

Open full view…

execute js everytime the page is shown

Jure Matoh
Mon, 09 Jun 2014 08:56:23 GMT

As I explained in @factfour's question, I have trouble with executing javascript each time I show a certain page. It seems that whatever I do the javascript executes only the first time the page is shown. I want to be able to execute js EACH time the page is shown.

Jure Matoh
Mon, 09 Jun 2014 09:05:54 GMT

Explanation: on browser back the JS is not executed. How can I make it execute?

Vladimir Kharlampidi
Mon, 09 Jun 2014 14:52:13 GMT

If you mean that you have JS (<script>) tags in Ajax loaded pages, you may parse them using these technic https://github.com/nolimits4web/Framework7/issues/70. Otherwise you need to use page callbacks

Jure Matoh
Tue, 10 Jun 2014 07:54:21 GMT

No, I have js methods defined and call them on pageInit. When I click on a link everything is fine. The problem is when I go deeper and want to go back (as in browser back button), it goes back but the javascript does not execute on pageInit (nor does it execute on pageAfterAnimation).

olanchuy
Tue, 10 Jun 2014 12:08:33 GMT

This is also the problem I'm facing, the back buttom seems do not load the last viewed page, that's why it's not triggered on clicking back, however you can run the function you want if you target the the back button. ex. $$('.back').click(function() { // run }; ); The only problem is when they swipe it back, I don't know if there's a callback function to it after it it's swiped back.

Jure Matoh
Tue, 10 Jun 2014 12:32:12 GMT

I'm not using the "soft" back, I'm using the browser's back...

Vladimir Kharlampidi
Tue, 10 Jun 2014 14:13:56 GMT

@olanchuy when you go back to previous preloaded page there is not 'pageInit' event for it. Use pageBeforeAnimation and pageAfterAnimation callbacks

Vladimir Kharlampidi
Tue, 10 Jun 2014 14:15:12 GMT

@Jure the same, use pageBeforeAnimation and pageAfterAnimation events If you need to do something each time the page is shown

Jure Matoh
Thu, 12 Jun 2014 09:11:31 GMT

thanks, this wasn't working for me before, I guess I had a bug. Now it works perfectly.

Mustafa Arslan
Thu, 12 Jun 2014 10:59:51 GMT

Hey jure could you share with us a sample code. I'm really curious about how you did it? I'm also trying to use browsers back but I couldn't trigger it correctly..

Jure Matoh
Thu, 12 Jun 2014 11:40:10 GMT

I have functions for each page I load. So, for mypage.jsp where I don't want tabbar, I do this: $$(document).on('pageInit', function (e) { var page = e.detail.page; if (page.name==='mypage') { mypage(); } ... ... ... }); $$(document).on('pageBeforeAnimation', function (e) { var page = e.detail.page; if (page.name==='mypage') { tabOff(); } else tabOn(); });