Communication between pages via JavaScript

4

I'm developing a web app, where each page has an option to filter, for example, one for brands, then the models of those brands, after, the cars and then the years of the car chosen.

I would like to know a way to communicate these pages by passing the chosen options on each page without using PHP , HTML / strong> and JavaScript .

Opening another window to you, using, for example, the code below:

function selectCarro(carro){
  window.marca = carro;
  var b = window.open("modelos.html");
  $(b).load(function(){
  b.marca = marca;
  b.atualiza();
  return;
  });
}

The problem is to open the page in the same window, for example with window.location or open using _self .

Any solution ??

    
asked by anonymous 02.09.2015 / 13:58

1 answer

4

One option I always suggest in these cases is localStorage and works on all of the most frequently used browsers .

LocalStorage saves a DOM string where you can put not only strings but also objects using JSON.stringify() and JSON.parse() , which erases the data with the end of the session.

Simple example of use:

var filtros = [{
    marca: "VW",
    ano: "2015",
    modelo: "Gol"
}];

localStorage.setItem("filtros", JSON.stringify(filtros));

var filtrosSalvos = localStorage.getItem("filtros");

console.log("filtrosSalvos", filtrosSalvos);

Fiddle

    
02.09.2015 / 14:19