Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

CQ and Javascript redirection

Avatar

Former Community Member

Trying to redirect to an EXTERNAL URL via javascript.
CQ blocks any attempts of reading or redirecting to external URL's.

How do I work around this?

Kind regards
Toby

1 Accepted Solution

Avatar

Correct answer by
Employee

You are correct that when the Content Finder is open, you can't redirect the content window to a different domain. If you want to support JavaScript redirects while the content finder is open (which I actually wouldn't recommend as that makes authoring difficult), then the script would be :

<script>window.top.location.href="http://www.google.com/";</script>

The second issue you mention is not a CQ restriction; it is a browser restriction and is something which can be addressed by having the target site (i.e. http://www.externalURL.com) adding support for CORS.

Regards,

Justin

View solution in original post

4 Replies

Avatar

Employee

Hi Toby,

What exactly do you mean? CQ doesn't put restrictions on reading or redirecting to external URLs.

Try dropping this:

<script>window.location.href="http://www.google.com/";</script>

Into /apps/geometrixx/components/page/body.jsp and you'll get redirected when you access /content/geometrixx/en/services/banking.html (for example).

Regards,

Justin

Avatar

Former Community Member

Hi Justin.

Attached your script to my page.
Instead of redirecting to google.com

The page is redirected to the following url:
http://localhost:4502/cf#_

Any jQuery.posts(), throws an error in my browser console:
"Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.externalURL.com This can be fixed by moving the resource to the same domain or enabling CORS."

Kind regards
Toby

Avatar

Correct answer by
Employee

You are correct that when the Content Finder is open, you can't redirect the content window to a different domain. If you want to support JavaScript redirects while the content finder is open (which I actually wouldn't recommend as that makes authoring difficult), then the script would be :

<script>window.top.location.href="http://www.google.com/";</script>

The second issue you mention is not a CQ restriction; it is a browser restriction and is something which can be addressed by having the target site (i.e. http://www.externalURL.com) adding support for CORS.

Regards,

Justin

Avatar

Former Community Member

Hi Justin.

Cool, solved.
Removed the /cf#/ from the URL, and was then able to redirect.

Thanks for your answer.

Kind regards
Toby