Hi Dina,
Welcome to the Unbounce community.
Can you please give us a bit more background information on what you are trying to accomplish.
If you give us a bit more details, I’m sure the community here can help you troubleshoot the issue.
Best,
Hristian
EDIT:
Here is a piece of code that would work, I just tested it:
(The original code was put together by Mark for this thread and had a delay timer on the redirect)
<br /> (function(){<br /> <br /> // URL for your redirect<br /> var url = '<a href="https://www.google.com'" rel="nofollow" title="Link: https://www.google.com'">https://www.google.com'</a>;<br /> <br /> window.location.href = url;<br /> <br /> })();<br /> <br />
However, consider all the implications of such redirects on your UX and SEO.
Thanks.
Will it work just as 301 redirect?
To your questions above - I want to redirect a click-thru visitor, just like 301.
The code I used I found in one of the threads here…
Hi Dina,
Can’t you just change the destination URL of the page that the user gets forwarded to on click through?
I’m a bit unclear as to why this needs a piece of custom script rather than just using the Unbounce native functionality?
Sorry if I’m missing something 🙂
Cheers
Stuart.
No, I cannot:) It can do me harm in terms of SEO (pages already indexed by Google). You should not just change the URL of a page on your web site - but rather make a redirect.
Thank you.
Hi Dina,
I think we are talking cross purposes here.
If you want to route the visitor to a different URL on a click through page, just change the URL that the button the visitor clicks points to.
I’m not suggesting changing a URL on your website, I wouldn’t recommend that without some kind of redirect anyway or SEO safeguarding practice.
If it’s a click through page… just change the target of the click.
Cheers
Stuart.
Maybe I misunderstood you. I need a regular 301 redirect - when a person clicks on this URL - it should be redirected to home page. That’s it.
Ok soz, crossed wires, thought we were talking about a click through landing page as mentioned above… I get a bit scatty on a Wednesday 🙂
Hristian’s code will do the job but I want to just add a couple of “be careful” points for you.
You can not send a 301 status code via Javascript any page rank of the old location will not be transferred to the new location.
Some browsers disable Javascript, think about including a link to the destination page in the body of your LP in case the redirect doesn’t fire.
It’s common to show a page that has a message saying, “This site has moved to … Your browser will be automatically forwarded in X seconds. Click here if your browser does not automatically forward you.”. It helps to cover up the “blink” of the page as it loads and the redirect is executed.
Apologies for the confusion to start with, Javascript automatic redirects for the purpose of 301 or 302 don’t work, but for user experience they are ok.
Cheers
Stuart.
You can redirect a web page via JavaScript using a number of methods. window.location.replace(…) is better than using window.location.href, because replace() does not keep the originating page in the session history, meaning the user won’t get stuck in a never-ending back-button fiasco.
If you want to simulate someone clicking on a link, use location.href
If you want to simulate an HTTP redirect, use location.replace
JavaScript redirect example:
// similar behavior as an HTTP redirect
window.location.replace("http://example.com");
// similar behavior as clicking on a link
window.location.href = "http://example.com";