简体   繁体   中英

local storage index.js cordova

I am following the cordova tutorial on tutorialpoints.com.

At Step 2 Adding Event Listeners to set and show local storage there is a sentence which is not easily comprehended by me precisely at: "Cordova security policy doesn't allow inline events so we will add event listeners inside index.js files."

What is that supposed to mean? Where should I put these inside the index.js?

document.getElementById("setLocalStorage").addEventListener("click", setLocalStorage);
document.getElementById("showLocalStorage").addEventListener("click", showLocalStorage);
document.getElementById("removeProjectFromLocalStorage").addEventListener("click", removeProjectFromLocalStorage);
document.getElementById("getLocalStorageByKey").addEventListener("click", getLocalStorageByKey);

var localStorage = window.localStorage;`

Inside variable app but outside the functions, or inside any of the functions?

It is driving me crazy!!!!

You should put it in document redy like

  document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById("setLocalStorage").addEventListener("click", setLocalStorage);
document.getElementById("showLocalStorage").addEventListener("click", showLocalStorage);
document.getElementById("removeProjectFromLocalStorage").addEventListener("click", removeProjectFromLocalStorage);
document.getElementById("getLocalStorageByKey").addEventListener("click", getLocalStorageByKey); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM