• i am running the woocommerce plugin and atelier theme on wp 4.3.1, latest version of each plugin.

    i am trying to perform a simple href redirect using pure js. Not php, not jquery, just js, and without resorting to child theme html mods.

    the pourpose of this redirect is allow a user to return to their referrer page after clicking on a link inside of an <a> element. so if they go from the home page to the cart page, they should return to the home page, and not be sent to the shop (or catalog) page, which is the default behavior, after they click on the “return to shop” box.

    the Atelier html is a follows:

    <a class="button wc-backward" href="https://needlepoint.land/index.php/catalog-2/">Return To Shop</a>

    my js function code is as follows:

    window.onload = function () {
    
            document.querySelector(".button.wc-backward").onclick = function() {
    
                var URLstring = document.referrer;  // works fine
    
                window.location.href = URLstring;  // ref unchanged
    
                setTimeout(function () {
                    window.location.href = URLstring; },100);  // same result
    
                return false;
    
        }
    }

    this works fine on github. (see Stackoverflow response )

    It appears something in WP is somehow blocking the redirect. I contacted Swiftideas (makers of Atelier), who sent me a custom jquery solution. I replaced my pure JS function with this, but same result.

    Query(document).ready(function() {
    
    var referrer = document.referrer;
    var defaultURL = 'https://needlepoint.land/index.php/catalog-2/';
    
    if ( referrer ) {
    jQuery("a.continue-shopping").prop("href", referrer);
    console.log(referrer);
    } else {
    jQuery("a.continue-shopping").prop("href", defaultURL);
    console.log("No refering URL set. Defaulting back to default cart URL.");
    }
    
    });

    There is definitely something on the server that is preventing the href from being redirected to a referrer page. Swiftideas state their code works in their dev env. It does not work in my production env, unfortunately.

    Does anyone have an idea why this is happening, and how to fix it? I have run out of ideas for fixes. Thank you!

The topic ‘href redirect not working’ is closed to new replies.