Is it possible to make an appendTo to another document?

1

Good morning.

Is it possible to clone a div from a webpage to another page?

Example:

Access my system and go to the "list" page.

In this page list, I have a div with id="testCount".

On this same page I have a button that when clicked opens a new page, called "edit".

What I wanted to do was copy the content I typed into the "list" page and when I opened the "edit" page this content would appear on this new page.

Can you do that?

Thank you

    
asked by anonymous 19.12.2016 / 15:04

1 answer

0

I will start from the premise that both pages belong to the same domain, but will not necessarily be opened in the same tab.

In the list page you can do something like.:

var testeConteudo = document.getElementById("testeConteudo");
var editar = document.querySelectorAll(".btn-editar");

var onEditarClick = function(event) {
    localStorage.setItem('testeConteudo', testeConteudo.value);
}

[].forEach.call(editar, function (elem, indice) {
    elem.addEventListener("click", onEditarClick)
});

When you open the editing page, you can recover as follows:

document.onreadystatechange = function () {
  if (document.readyState === "interactive") {
    var testeConteudo = document.getElementById("testeConteudo");
    testeConteudo.value = localStorage.getItem('testeConteudo');
    localStorage.removeItem('testeConteudo');
  }
}
    
19.12.2016 / 15:17