我正在尝试通过放置在域 B 中的内联 JavaScript 代码从域 B 读取域 A 设置的 cookie(我知道 cookie 的名称)。
域 B 内联 javascript 代码:
<script type="text/javascript">
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://domainA.com/classifiead/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
http://domainA.com/classifiead/embed.js包含:
$("#jsonpbtn2").click(function() {
var url = 'http://domainA.com/classifiead/content2.php?callback=?';
// var id = info;
$.getJSON(url, null, function(data) {
$('#textDiv').append(data.somecookie);
});
});
http://domainA.com/classifiead/content2.php包含:
<?php
header('Content-type: application/json');
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Headers: Content-Type, *");
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
$rtnjsonobj->id = 'test skdfbslkdj';
$rtnjsonobj->somecookie =$_COOKIE['thisweb_last_75'];
echo $_GET['callback']. '('. json_encode($rtnjsonobj) . ')';
?>
这甚至可能吗?