Send a Map between different html Javascript files

1

Hi, I am working with 2 htlm's ( login.html and assistance.html ), each with its respective javascript ( login.js and assistance.js ), in login.js I create a user map (usersMap).

How could you use usersMap in assistance.js so you do not have to create it again?

login.js

var usersMap = new Map();
var rootRef = firebase.database().ref().child("Users");
rootRef.on("child_added",  function (snap) {
    var userId = snap.child("UserId").val().toString();
    var nameUser = snap.child("Name").val().toString();
    var password= snap.child("Password").val().toString();
    var sede = snap.child("Sede").val().toString();
    var isAdmin = snap.child("IsAdmin").val().toString();

    var newUser = new User(userId, nameUser, password, sede, isAdmin);
    usersMap.set(userId, newUser);
});

assistance.js

$(document).ready(function () {
var position = location.toString().search("userId");
var userId = location.toString().substring(position);


var marcarBtn = $('#marcarBtn');

marcarBtn.on('click',marcarAsistencia);

function marcarAsistencia(){
    var currentUser = usersMap.get(userId);
}});

I tried to put the following in attendance.html, but there is no result.

<script src="js/login.js"></script>
<script src="js/asistencia.js"></script>
    
asked by Luis Manrique Julca 16.12.2016 в 21:29
source

1 answer

0

If they are two different pages I think you will not be able to directly because the content is loaded to each request of the page (including the scripts).

You can do several things:

  • Move to a SinglePage approach using any framework (angularjs for example)
  • Use some means of browser storage (localstorage, sessions, ....), although I do not recommend it.
  • Use a backend, collect that information and pass it to the second page.
answered by 23.12.2016 в 12:30