javascript - how to copy div content to another page

前端 未结 4 1283
心在旅途
心在旅途 2021-01-01 08:03

I would like to make an automatic copy of a div content from page 1 an paste it in a div on page 2 ? What\'s the best, easiest way to achieve this ?

4条回答
  •  梦毁少年i
    2021-01-01 08:44

    For javascript only and with HTML5 support,

    Page 1:

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

    Page 2:

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

提交回复
热议问题