Redirect

Dear all,

hope this email finds you well.

We need to automatically redirect a page to a new link after 10 seconds. I attempted to add the code to the head section in the settings of the landing page, but not working.
"Redirect Error

It looks like some code on your page caused a redirect to an unexpected URL, preventing the editor from working properly. Please wrap any javascript redirect code on your page with editor check conditionals. See the knowledge base for more information."

Thank you

Hi @znajem,

if you’re putting the script into the head section in the settings the script will be executed inside the page builder which will lead to the error you’ll see.
You can wrap it in a simple if/unless statement like this

{% unless is_in_page_editor %}
<script>
document.addEventListener("DOMContentLoaded", function() {
 setTimeout(function() {
 window.location.href = "https://www.example.com";
 }, 
 10000); // 10000 milliseconds = 10 seconds
});
</script>
{% endunless %}

change the window.location.href to the url you’d like to redirect to and modify the delay if needed.

The {% unless is_in_page_editor %} statement will execute the script if you’re not in the page builder.

You can find more about this variable here in the docs

best,

Anton

Hello Anton,

Thank you for your reply.

The redirect works properly when using the URL (Thank You Page), but in HubSpot, I always receive an error message stating that the page has been blocked by Chrome. Is this normal?

Hi @znajem, do you mean inside the page-editor?
If so - yes it’s normal because you’re trying to open a non HubSpot page inside HubSpot which is not possible.

Also you might want to put the redirect script to the external page if you’re redirecting from HubSpot to somewhere else

best,

Anton