0

Hi in my application i am navigating from one div to another div using the below code,

$.mobile.navigate( "#formsEnterId", { info: "info about the #formsEnterIdhash" });

$("#formsEnterId").on('pagebeforeshow', function (event, data) {
            console.log("Entered page before show::",data);    //How to fetch the info here??
        });

In the pagebeforeshow event i want to fetch the info attribute.I don't know how to fetch the info attribute.But the page navigation is successful.

Also i used $.mobile.changepage but no luck.

Please someone assist me to get the info attribute in pagebeforeShow event. I already saw the related answers posted in Pass parameter between pages using jquery mobile

But that doesn't solve my problem because my page navigate script and pagebeforeshow event are under different closures.

Community
  • 1
  • 1
VelNaga
  • 3,593
  • 6
  • 48
  • 82

1 Answers1

0

As everything is loaded into the DOM we can create a global object for data storing.

live example : http://jsfiddle.net/Gajotres/9KKbx/

var storeObject = {
    parameter1: null,
    parameter2 : null
}
// Store object
$(document).on('pagebeforeshow', '#second', function(e, data){    
    alert("My name is " + data.prevPage.find('#test-input').val());
});

Another way is storing variable in local storage

$(document).on('pagebeforeshow', '#index', function(){      
    $(document).on('click', '#change-page-button', function(){    
        // store some data
        if(typeof(Storage)!=="undefined") {
              localStorage.firstname="Dragan";
              localStorage.lastname="Gaic";           
        }
        // Change page
        $.mobile.changePage("#second");
    });   
});

$(document).on('pagebeforeshow', '#second', function(){      
    alert('My name is ' + localStorage.firstname + ' ' + localStorage.lastname);
    // Lets change localStorage data before we go to the next page
    localStorage.firstname="NewFirstNeme";
    localStorage.lastname="NewLastName";   
});

$(document).on('pagebeforeshow', '#third', function(){      
    alert('My name is ' + localStorage.firstname + ' ' + localStorage.lastname);
});
Dibish
  • 9,133
  • 22
  • 64
  • 106