How to send an APPEND between HTML pages

Asked

Viewed 48 times

0

Hello! What I would like is that when my user click on "add cart" on page 1, an append is added on page 2.

Currently I have the append configured correctly on my page 2

HTML PAGE 1:

    <button type="button" id="btnCompra" class="btn btn-danger">
    <i class="fas fa-shopping-basket"></i> Adicionar ao carrinho</button>

HTML PAGE 2:

    <div class="container-fluid divProdCarrinho"> 
        <div class="row" id="modeloProdutos">
           <div class="col-sm-12 col-md-4 col-lg-6"> 
             <img src="img/arroz.jpg" id="imagenzinha"> 
             <p id="descricaoProduto">...</p> 
    </div> </div> </div> 

JAVASCRIPT (which works because all elements are from the same page):

$(document).ready(function(){
    $('#botaoPagina1').click (function(){
        var template = $('.divProdCarrinho').html();
        $("#bodyPrincipal").append(template);
    }); 

JAVASCRIPT (I would like it to work, where butonAdd is page 1 element)

$(document).ready(function(){
    $('#botaoPagina2').click (function(){
        var template = $('.divProdCarrinho').html();
        $("#bodyPrincipal").append(template);
        alert(template);
    }); 
  • How so on "page 2"? it is only possible to do append on the page that is loaded in the browser. It was not clear how this navigation is, but you need to pass a parameter to the other page, by querystring for example, and append in the script of the page itself

  • 1

    Use the localStorage to pass data from one page to another.

  • Ricardo basically I want to give an append on page 2 with elements of page 1, but I do not know if it is possible

  • Valdeir is possible I save the elements in localStorage of page 1 and give an append with this information on page 2?

  • @Weslleyfillipe with the localStorage yes. You save the HTML on one page, and by loading the other, you capture the saved HTML on the previous page.

  • Valdeir, I tried to give a "localStorage.setItem('modeloProduto', $('.divProdCarrinho').html();" but returned "Undefined", since this div only exists on page 2. My goal was to add a div on page 2 after clicking the button on page 1

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.