LoginSignup
4
4

More than 5 years have passed since last update.

OnsenUIでページ推移時にJSを発動する

Posted at

Monacaのテンプレート「Onsen UI ナビ付きタブバー」で新規プロジェクトを作成しました。
ページ推移時にJSを発動させる方法です。

function onDeviceReady() {
    tabbar.on('postchange', function(e) {
        //Home
        myNavigator.on('postpush', function(e) {
            console.log('Home')
        });

        var page = e.index;
        if(page==1){
            console.log('page1');
            //page1の中でpushPage
            mySchedule.on('postpush', function(e) {
                console.log('page1-1');
            });
        }else if(page==2){
            console.log('page2');
        }

    });

}//onDeviceReady

var event = typeof cordova === 'undefined' ? 
                              'DOMContentLoaded' : 'deviceready';
document.addEventListener(event, onDeviceReady, false);
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4