Set ons-navigator page attribute dynamically?
-
Hi,
I’m trying to set the ons-navigator page attribute dynamically using jQuery/Javascript but the attr doesn’t really work for some reason!
This is my code:
var currentPage = localStorage.getItem('curPage'); if(currentPage =='' || curPage ===null ){ var ba = $("#navi").attr("page"); alert(ba); }else{ }
But I always get undefined in the **alert(ba); **and it never changes the navi’s page attribute!
Is this even possible and if so how?
Thanks in advance.
-
@Jackson Sorry up front for simply linking to another answer of mine, but I am working from my phone. Here is working code of setting the page for a navigator:
-
@munsterlander Currently I’m doing it exactly what you’ve shown in your answer in other thread which is using localstorage etc… But i thought there must be an easier way of doing this which is accessing the page attribute!
-
@Jackson The
page
attribute only works at initialization. You can useresetToPage
method instead of modifying that I guess.
-
@Jackson You don’t have to use localstorage. That was for a specific use case. You just need document.getElementById (‘yourNavId’).pushPage (‘yourPage.html’).
Sorry for the lack of formatting, I’m still on my phone in an airport at the moment.