CQ and Javascript redirection | Community
Skip to main content
October 16, 2015
Solved

CQ and Javascript redirection

  • October 16, 2015
  • 4 replies
  • 1760 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by JustinEd3

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

4 replies

Adobe Employee
October 16, 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

October 16, 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

JustinEd3Adobe EmployeeAccepted solution
Adobe Employee
October 16, 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

October 16, 2015

Hi Justin.

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

Thanks for your answer.

Kind regards
Toby