내 요구 사항을 검색하여 내 질문에 대한 답변을 찾았습니다. 그러나 나는 그것을 작동하게 만들 수 없었다. 그러므로 여기에 나의 요구 사항을 게시 할 생각을했습니다.iframe에서 크로스 도메인의 쿠키에 액세스 할 수 없습니다.
내 웹 사이트는 타사 공급 업체에서 호스팅하며 해당 서버를 제어 할 수 없습니다. HTML 페이지 중 하나에 iframe이 설정되어 있습니다. 이 iframe은 내 서버를 가리키며 기본 페이지에서 공급 업체가 설정 한 쿠키에 액세스 할 수 있어야합니다. 이것을 시도하기 위해 두 개의 html 페이지를 만들었습니다. 하나는 SetCookie.html, 다른 하나는 GetCookie.html으로 명명됩니다. 둘 다 다른 컴퓨터에 있습니다. 어떤 제안이
SetCookie.html
<html>
<head>
<title>Set Cookie</title>
</head>
<body>
<script type="text/javascript">
function setCookie() {
var cookieValue = document.getElementById("txtCookie").value;
var cookieName = "TestCookie";
document.cookie = cookieName + "=" + cookieValue;
document.getElementById("tdCookieMessage").innerHTML = cookieName + "=" + cookieValue + " is set!";
}
</script>
<table>
<tr>
<td>
Cookie
</td>
<td>
<input type="text" id="txtCookie" value="" />
</td>
<td>
<input type="button" id="btnGetCookie" onclick="setCookie();" value="Set Cookie!" />
</td>
</tr>
<tr>
<td colspan="3" id="tdCookieMessage">
</td>
</tr>
</table>
<table>
<tr>
<td>
<iframe src="http://myServer/GetCookie.html"></iframe>
</td>
</tr>
</table>
</body>
</html>
GetCookie.html
<html>
<head>
<title>Get Cookie</title>
<script type="text/javascript">
function getCookie(cookieName) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == cookieName) {
document.getElementById("tdCookie").innerHTML = unescape(y);
expireCookie(cookieName);
}
}
}
function expireCookie(cookieName) {
document.cookie = cookieName + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}
</script>
</head>
<body>
<table>
<tr>
<td>
<input type="button" id="btnGetCookie" onclick="getCookie('TestCookie');" value="Test Cookie Value is: " />
</td>
<td id="tdCookie">
</td>
</tr>
</table>
</body>
</html>
감사합니다 : 아래의 소스 코드를 찾아주세요.
페이지가있는 도메인에 설정된 쿠키 만 페이지로 전송됩니다. IE는 mywebsite.com에 있으며 theirdomain.com에 있습니다. 귀하는 쿠키를받지 못하며 귀하의 쿠키를받지 못합니다. –