window.location.href = 'https://example.com'
const redirectUrl = 'https://example.com';
window.location.replace('https://example.com');
或:
window.location.href = redirectUrl;
除了Safari以外,所有浏览器都可以很好地工作。在野生动物园中,不会发生重定向,并且控制台中没有明显的错误。 我还通过在浏览器控制台中粘贴以下内容进行了测试:
window.location.href = 'https://example.com';
safari,同样的问题仍然存在 - 没有发生。
我怀疑这可能与CloudFront设置有关。我应该检查是否有任何特定的云层配置,以确保重定向在Safari中正确起作用?
safari块跨站点跟踪(ITP-智能跟踪预防)
Safari具有ITP(智能跟踪预防),如果涉及第三方cookie或交叉孔请求,可以阻止客户端重定向。
If your redirect goes to a different domain, Safari might block it without any warning or message.
Try setting window.location.assign() instead of window.location.href
window.location.assign("https://example.com");
assign() works better in Safari for some cases.
您还可以将Meta Refresh用作服务器侧后备。
https://example.com", "_self");
This explicitly tells Safari to open in the same tab.