I have the following URLs on a page:

<a class="mylink" href="http://www.example.com/old-product1" />
<a class="mylink" href="http://www.example.com/old-product2" />
<a class="mylink" href="http://www.example.com/old-product3" />

And essentially I want take the user from /old-product to /new-productwithout updating the URLS on the page in the source. I am using the following JavaScript to inject new URLS into the source.

$(".mylink a").each(function(){
        var urlSplit = $(this).attr('href').split("product");
            var pid = urlSplit[urlSplit.length-1];
            window.location.href = "http://www.example.com/new-product"+pid;
        return false;

What is the SEO implication of using JavaScript for taking a user from a defined link in href to some other link?

1 Answer 1


It's considered link cloaking, the major search engines will not appreciate this behaviour, nor will users. You should always adopt a transparent links policy, that way you run no risk of annoying your users or being punished by the search engines.

301 Redirects

If you have new pages, new products etc, then the correct method would be to use a 301 redirect from old page, to new page, this way not only do you keep search engines happy, you keep your visitors happy too, assuming that old product, is related to new product.

The other great thing about a 301 redirect is that you don't need to edit code source, simply apply your rules to your .htaccess, or IIS config, and the rest would be done for you. Finally, a 301 redirect will ensure that page rankings are being passed from old to new, while a JavaScript injection most likely won't.

  • its not redirect essentially, as redirect means its a http call to old product call and it gets redirected 302 from front-end. But its just changing the link altogether to some other link, as i want old-product link to remain crawled for seo, but take user to new product page from here just for testing
    – abhinsit
    Aug 25, 2016 at 11:03
  • Its cloaking period... never serve one page for search engines, and then another for users... your asking for a penalty, dislike it or not, this is how Google operates. Accept it, or run the risk of being slapped. Aug 27, 2016 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.