U
SOLVED, but I’ll keep this up for any other people who might happen to come across a similar issue. :)
Solution: I changed the second ‘else if’ statement to an ‘if’ statement. So:
else if (page.id === ‘page1’) {
page.querySelector(’#push-button-page3’).onclick = function() {
document.querySelector(’#myNavigator’).pushPage(‘page3.html’, {data: {title: ‘Page 3’}});
changed to:
if (page.id === ‘page1’) {
page.querySelector(’#push-button-page3’).onclick = function() {
document.querySelector(’#myNavigator’).pushPage(‘page3.html’, {data: {title: ‘Page 3’}});
Original:
Thank you for the response. For some reason I’m not making the connection using the tutorial. I’ll give it more of a go. Here’s the code I tried making that didn’t work. Going to page 2 works, but when I click page 3 it doesn’t go anywhere.
<!DOCTYPE html>
<html>
<head>
<link rel=“stylesheet” href="./css/onsenui.css">
<link rel=“stylesheet” href="./css/onsen-css-components.min.css">
<script src="./js/onsenui.min.js"></script>
<script>
document.addEventListener(‘init’, function(event) {
var page = event.target;
if (page.id === ‘page1’) {
page.querySelector(’#push-button’).onclick = function() {
document.querySelector(’#myNavigator’).pushPage(‘page2.html’, {data: {title: ‘Page 2’}});
};
} else if (page.id === ‘page1’) {
page.querySelector(’#push-button-page3’).onclick = function() {
document.querySelector(’#myNavigator’).pushPage(‘page3.html’, {data: {title: ‘Page 3’}});
}} else if (page.id === ‘page2’) {
page.querySelector(‘ons-toolbar .center’).innerHTML = page.data.title;
} else if (page.id === ‘page3’) {
page.querySelector(‘ons-toolbar .center’).innerHTML = page.data.title;
} });
</script>
</head>
<body>
<ons-navigator swipeable id=“myNavigator” page=“page1.html”></ons-navigator>
<template id="page1.html">
<ons-page id="page1">
<ons-toolbar>
<div class="center">Page 1</div>
</ons-toolbar>
<p>This is the first page.</p>
<ons-button id="push-button">Page 2</ons-button>
<ons-button id="push-button-page3">Page 3</ons-button>
</ons-page>
</template>
<template id="page2.html">
<ons-page id="page2">
<ons-toolbar>
<div class="left"><ons-back-button>Page 1</ons-back-button></div>
<div class="center"></div>
</ons-toolbar>
<p>This is the second page.</p>
</ons-page>
</template>
<template id="page3.html">
<ons-page id="page3">
<ons-toolbar>
<div class="left"><ons-back-button>Page 1</ons-back-button></div>
<div class="center"></div>
</ons-toolbar>
<p>This is the third page.</p>
</ons-page>
</template>
</body>
</html>