2017-09-10 104 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服務器來託管您的頁面。 –