【发布时间】:2021-02-18 11:11:35
【问题描述】:
虽然 IFrame 和 xyz.com 正在 IFrame 中加载,但我正在尝试访问跨站点 url。
在 xyz.com 中,我们使用了 asp.net 会员模块,并且我们正在使用 SetAuthCookie。
FormsAuthentication.SetAuthCookie(userName, false);
以前,我们可以通过使用以下逻辑,通过引用者访问顶部框架 href,在 safari 中访问这些身份验证 cookie。
<script>
window.onload = function () {
if (navigator.userAgent.indexOf('Safari') != -1 && (navigator.userAgent.indexOf('iPhone') != -1 || navigator.userAgent.indexOf('iPad') != -1)) {
var cookies = document.cookie;
if (top.location != document.location) {
if (!cookies) {
href = document.location.href;
href = (href.indexOf('?') == -1) ? href + '?' : href + '&';
top.location.href = href + 'reref=' + encodeURIComponent(document.referrer);
}
} else {
ts = new Date().getTime(); document.cookie = 'ts=' + ts;
rerefidx = document.location.href.indexOf('reref=');
if (rerefidx != -1) {
href = decodeURIComponent(document.location.href.substr(rerefidx + 6));
window.location.replace(href);
}
}
var redirectValue = document.getElementById('hgvRedirectValueHiddenField').value;
if (redirectValue != "") {
window.open(redirectValue, '_self');
}
}
}
</script>
但是对于最新的更新,safary 不允许设置
top.location.href = href + 'reref=' + encodeURIComponent(document.referrer);
auth cookie 似乎不再允许并出现以下错误
顶层窗口尝试导航的框架是 跨域或不受信任且用户从未与 框架。
由于我无法访问 ABC.com 并且无 cookie 表单身份验证对我们来说似乎发生了巨大变化,因此该问题的解决方法是什么。
是否可以要求用户从 iframe 页面内部接受 cookie 并设置 cookie?
【问题讨论】:
标签: javascript authentication cookies iframe safari