CQ and Javascript redirection

Avatar

Avatar

Tboness

Avatar

Tboness

Tboness

15-10-2015

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

justin_at_adobe

Employee

Avatar

justin_at_adobe

Employee

justin_at_adobe
Employee

15-10-2015

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

Answers (3)

Answers (3)

Avatar

Avatar

Tboness

Avatar

Tboness

Tboness

15-10-2015

Hi Justin.

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

Thanks for your answer.

Kind regards
Toby

Avatar

Avatar

Tboness

Avatar

Tboness

Tboness

15-10-2015

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

Avatar

justin_at_adobe

Employee

Avatar

justin_at_adobe

Employee

justin_at_adobe
Employee

15-10-2015

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