Is it possible to make an appendTo for another document?

Asked

Viewed 29 times

1

Good morning.

It is possible to clone a div from a webpage to another webpage?

Example:

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

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

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 on the "list" page and when opening the "edit" page this content appeared on that new page.

You can do that?

Thank you

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 opening 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');
  }
}
  • thanks for the example, but it didn’t work. I’ll research more on this. I need to take the contents of page 1.html and play on page 2.html ... I’ll see if I can find something with Jquery.

Browser other questions tagged

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