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 there,
You’re on the right track with wanting to redirect a page after a delay, but HubSpot’s landing page editor has specific protections in place to avoid redirect loops or broken editor experiences. That’s why you’re seeing the “Redirect Error” and the warning about wrapping your code with editor conditionals.
To implement a timed redirect without breaking the page editor, you need to use HubSpot’s editor check conditional around your JavaScript. Here’s a safe code snippet you can add to the Footer HTML or Head HTML of your landing page settings:
<script> if (window.location.href.indexOf(‘hs_preview’) === -1 && window.location.href.indexOf(‘content-preview’) === -1) { setTimeout(function() { window.location.href = "https://your-new-url.com"; }, 10000); // 10 seconds = 10,000 milliseconds }
</script>
HubSpot uses special preview modes (hs_preview or content-preview) in the editor. The if condition checks that the user is not in preview mode before triggering the redirect. This ensures:
-
Your editor remains accessible.
-
The redirect only runs for actual visitors.
If your page is getting indexed by search engines and you want to preserve SEO value, consider using a 301 redirect via HubSpot’s URL Redirects tool instead of JavaScript-based redirection. But for timed transitions or temporary behavior, this JS method is acceptable.
Let me know if this helps, or if you have any other questions!
Was I able to help answer your question? Help the community by marking it as a solution.
Hi Brandon Woodruff,
Thank you for your reply.