I'm encountering an issue where redirection using window.location.replace('')
or window.location.href = ''
It works fine on most browsers (Chrome, Firefox, Edge), but it does not work in Safari.
My website is hosted on AWS CloudFront and the logic for redirection is as simple as:
const redirectUrl = '';
window.location.replace('');
or:
window.location.href = redirectUrl;
In all browsers except Safari, this works perfectly. In Safari, no redirection occurs, and there's no visible error in the console. I have also tested by pasting the following in the browser console:
window.location.href = '';
In Safari, the same issue persists—nothing happens.
I suspect this may have something to do with CloudFront settings. Are there any specific configurations for CloudFront that I should check to ensure redirection works correctly in Safari?
I'm encountering an issue where redirection using window.location.replace('https://example.com')
or window.location.href = 'https://example.com'
It works fine on most browsers (Chrome, Firefox, Edge), but it does not work in Safari.
My website is hosted on AWS CloudFront and the logic for redirection is as simple as:
const redirectUrl = 'https://example.com';
window.location.replace('https://example.com');
or:
window.location.href = redirectUrl;
In all browsers except Safari, this works perfectly. In Safari, no redirection occurs, and there's no visible error in the console. I have also tested by pasting the following in the browser console:
window.location.href = 'https://example.com';
In Safari, the same issue persists—nothing happens.
I suspect this may have something to do with CloudFront settings. Are there any specific configurations for CloudFront that I should check to ensure redirection works correctly in Safari?
Share Improve this question edited Jan 27 at 8:16 Krzysztof Majewski asked Jan 27 at 8:07 Krzysztof MajewskiKrzysztof Majewski 2,5344 gold badges28 silver badges52 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 0Safari Blocks Cross-Site Tracking (ITP - Intelligent Tracking Prevention)
Safari has ITP (Intelligent Tracking Prevention), which can block client-side redirects if they involve third-party cookies or cross-origin requests.
If your redirect goes to a different domain, Safari might block it without any warning or message.
You can try by setting window.location.assign() instead of window.location.href
window.location.assign("https://example.com");
assign() works better in Safari for some cases.
You can also use meta refresh as a server-side fallback.
https://example.com", "_self");
This explicitly tells Safari to open in the same tab.
window.location.replace('https://www.google.com')
? Does it only not work on cloudfront host website ? – vht981230 Commented Jan 30 at 5:12window.onbeforeunload = null
. Have you tried redirection on a blank web-page hosted from cloudfront to see if there are any issues – vht981230 Commented Jan 31 at 5:08