1

Suppose i know the id of a div from other page - can plain java script can copy the content from one page to other page? This is my function with empty place for your answer (if that possible):

function copyPaste() {
  var dataPage2 = 'path-to-data-div-from-page2'.innerHTML;

  document.write ("<section id='example'></section>");
  document.getElementById("example").innerHTML = dataPage2;
}
A. Meshu
  • 4,053
  • 2
  • 20
  • 34
  • What do you mean by another page? – Jordan Soltman May 10 '17 at 18:54
  • I thin you can look at this: http://stackoverflow.com/questions/3203530/accessing-the-content-of-other-tabs-in-browser – Mario Santini May 10 '17 at 18:54
  • javascript is running on the html DOM and its parent/root scope it the document. So it can only be act on one document at a time. You can load the **path-to-data-div-from-page2** page and store it's content in localStorage and can be accessed in another page while loading. – Jijo Cleetus May 10 '17 at 18:56

2 Answers2

0

Page 1:

var pageContent = document.getElementById("myDiv1").innerHTML; 
sessionStorage.setItem("page1content", pageContent);

Page 2:

document.getElementById("myDiv2").innerHTML=sessionStorage.getItem("page1content");

Credits: https://stackoverflow.com/a/22245779/5192105

Community
  • 1
  • 1
Sachin Bahukhandi
  • 2,378
  • 20
  • 29
0
function copyPaste() {

document.write ("<div id='test' style='display:none' ></div>");

$( "#test" ).load( "http:url_of_web_Page #id" );

 var dataPage2 = $('#test').innerHTML;

 document.write ("<section id='example'></section>");
 document.getElementById("example").innerHTML = dataPage2;
 }
Subi
  • 107
  • 8