That’s what I thought. Thanks.
So now I have decided to have the code executed only on the index page, which is named home:
$$(document).on('page:init', '.page[data-name="home"]', function (e) {
// Do something here when page with data-name="about" attribute loaded and initialized
alert('home page.');
localforage.setItem('name', 'hey').then(function () {
return localforage.getItem('name');
}).then(function (value) {
// we got our value
alert("---"+value)
}).catch(function (err) {
// we got an error
alert("error"+err);
});
});
it doesn’t work.
But when I add to other pages, it does. I don’t quite get it why. Here’s my code for it on index.html:
<!-- Your main view/tab, should have "view-main" class. It also has "tab-active" class -->
<div id="view-home" class="view view-main tab tab-active">
<!-- Page, data-name contains page name which can be used in page callbacks -->
<div class="page" data-name="home">
<!-- Top Navbar -->
<div class="navbar">
<div class="navbar-inner">
<div class="left">
<a href="#" class="link icon-only panel-open" data-panel="left">
<i class="icon f7-icons ios-only">menu</i>
<i class="icon material-icons md-only">menu</i>
</a>
</div>
<div class="title sliding">RateMyFace</div>
<div class="right">
<a href="#" class="link icon-only panel-open" data-panel="right">
<i class="icon f7-icons ios-only">menu</i>
<i class="icon material-icons md-only">menu</i>
</a>
</div>
</div>
</div>
<!-- Scrollable page content-->
<div class="page-content" id="geoloc">
<div class="block no-hairlines">
<!-- block content -->
test
</div>
</div>
</div>
</div>
Any idea what’s wrong with it?
EDIT: I ran this code
// In page events:
$$(document).on(‘page:init’, function (e, page) {
console.log(page);
})
and I noticed that the index age isn’t on the log.
Object { app: {…}, view: {…}, router: {…}, "$el": Object […], el: div.page.page-current, "$pageEl": Object […], pageEl: div.page.page-current, "$navbarEl": {…}, navbarEl: undefined, name: "explore", … }
app.js:88:3
Object { app: {…}, view: {…}, router: {…}, "$el": Object […], el: div.page.page-current, "$pageEl": Object […], pageEl: div.page.page-current, "$navbarEl": {…}, navbarEl: undefined, name: "messages", … }
app.js:88:3
Object { app: {…}, view: {…}, router: {…}, "$el": Object […], el: div.page.page-current, "$pageEl": Object […], pageEl: div.page.page-current, "$navbarEl": {…}, navbarEl: undefined, name: "settings", … }
app.js:88:3