2017-09-10 105 views
0

我从父窗口由下面的代码打开一个子窗口:如何在子窗口中获取父窗口标签的html?

​​

在子窗口我想要得到的父窗口body标签HTML。所以我用下面的代码:

 <html> 
<head> 

</head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
<script type="text/javascript" language="javascript" src="html2canvas.min.js"></script> 
<script type="text/javascript" language="javascript" src="html2canvas.js"></script> 

<script type="text/javascript"> 

    function capture() { 
      window.alert('test'); 

      html2canvas(window.opener.$("body") 
      ,{ 
       onrendered: function (canvas) {      
          var imgString = canvas.toDataURL("image/png"); 
          window.open(imgString); 

       } 
      } 
     ); 
    } 
</script> 

<body id="d" onload="capture()"> 

<button id="button1" name="NiceButton" onclick="capture()">click here</button> 

</body> 
</html> 

但我收到以下错误:

TypeError: window.opener.$ is not a function 

我怎样才能解决这个问题?

我需要做什么: 我需要得到父窗体标签的innerHTML的试用版清单下面的代码工作?

alert($("window.opener.body")) ; 
+0

更换您的拍摄功能,您似乎并没有被包括在jQuery的第一页。 – skirtle

+0

我不需要在第一页中包含jQuery。 Jquery在该页面中不需要。 –

+0

??但是你在第一页上指的是jQuery? – Teemu

回答

1

function capture() { 
     window.alert('test'); 

     html2canvas(window.opener.document.body 
     ,{ 
      onrendered: function (canvas) {      
         var imgString = canvas.toDataURL("image/png"); 
         window.open(imgString); 

      } 
     } 
    ); 
} 
+0

在chrome中出现错误。 “阻止了原始帧”null“访问跨源帧。” –

+0

你需要一些主机来处理你的本地主机或你的域名。您可以使用xampp,wamp或任何Web服务器来托管您的页面。 –