从父窗口获取iFrame子项的cookie

时间:2018-07-06 06:12:45

标签: javascript jquery html cookies

我在localhost:8080有一个页面,其中有一个iframe在localhost:4040。现在我需要从localhost:8080获取localhost:4040中的cookie

我尝试了以下代码,但这仅在localhost:8080中显示cookie

<iframe src="http://localhost:4040" width="250px" height="250px" id="targetUrl"></iframe>
<script>
var $iframe = $('#targetUrl');
$iframe.ready(function() {
  var strVal = '';
  var doc = document.getElementById('targetUrl').contentWindow.document;
  console.log(doc.cookie);
  console.log(document.getElementById("targetUrl").contentDocument.cookie);
      });</script>

0 个答案:

没有答案