- Button component.
In the previous example, the "Previous" and "Next" buttons are found on the web page, we are going to use the Button component.
To insert the page number in the JavaScript code we will use a cookie.
The code will continually read the state of that cookie using a Timer.
For the use of cookies we will follow these tutorials:
https://community.appinventor.mit.edu/t/cookies-with-javascript-webviewer/63411
https://www.w3schools.com/js/js_cookies.asp
//////////// Cookies ////////////////////////////////
let myVar = setInterval(myTimer,100);
function myTimer() {
const d = new Date();
document.getElementById("demo").innerHTML = d.toLocaleTimeString() + " page: " + getCookie("page");
_CURRENT_PAGE = getCookie("page") * 1;
if (old_CURRENT_PAGE != _CURRENT_PAGE && _CURRENT_PAGE > 0 && _PAGE_RENDERING_IN_PROGRESS == 0){
showPage(_CURRENT_PAGE);
}
old_CURRENT_PAGE = _CURRENT_PAGE;
}
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}