最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

amazon web services - Safari not redirecting using window.location.replace or window.location.href on a CloudFront-hosted websit

programmeradmin4浏览0评论

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
  • 1 There's no way this has anything to do with CloudFront. This is purely an issue with the way Safari handles that JavaScript code. Possible duplicate: stackoverflow.com/questions/31223216/… – Mark B Commented Jan 27 at 14:23
  • @MarkB I checked this thread and lots of people still have this issue. Look at comments there – Krzysztof Majewski Commented Jan 27 at 20:22
  • Does the safari console command work if you go to regular website like youtube.com and enter the command in the console like say window.location.replace('https://www.google.com') ? Does it only not work on cloudfront host website ? – vht981230 Commented Jan 30 at 5:12
  • @vht981230 It doesn't work just on my website(s) hosted on CloudFront. On other websites line YouTube, Facebook, stack overflow the redirection from console works without any issue. – Krzysztof Majewski Commented Jan 30 at 15:15
  • Oh I see, could you share your html and javascript code of the cloudfront-hosted web page you're redirect from? I think there could be some part of the html or javascript elements in the web page that might have disable redirection by doing something like window.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
 |  Show 1 more comment

1 Answer 1

Reset to default 0

Safari 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论