如何将当前页面内容附加到另一个页面?

我必须将页面一个是源页面另一个是复制,我需要将一些div元素传递给其他页面体。 我做了一半,这里我用了setTimeOut函数怎么办没有超时function? 和浏览器应显示url。

来源页面:

      function copyCon(){ var p = document.getElementById("1"); var p_prime = p.cloneNode(true); var w = window.open('printcopy.html'); setTimeout(function(){ w.document.body.appendChild(p_prime); }, 1000); }   

this is a test heading

test Paragraph

复制:

       

有没有办法访问复制页面的元素和执行function?

您可以使用$ .get函数( 文档 )来实现。

在文件中,您要从复制中追加元素(假设您有一个名为div_you_want_to_be_append的div):

 $.get('source.php', function (data) { $('#div_you_want_to_be_append').append(data); }); 

避免新HTML标记的最佳方法是在PHP中包含要复制到新文件的内容,并将其包含在源代码中并调用$ .get函数(在我的示例中为file: source.php

我自己找到了解决方案

 function copyCon(){ var w = window.open('printcopy.html'); w.onload = function(){ var p = document.getElementById("1"); var p_prime = p.cloneNode(true); w.document.body.appendChild(p_prime); }; } 

谢谢你的支持