Digital experiences for all disciplines
New Landing › How can we help? › Atelier › href redirect not working
New Landing › How can we help? › Atelier › href redirect not working
- This topic has 31 replies, 4 voices, and was last updated 9 years by David Martin – Support.
-
Posted in: Atelier
-
September 17, 2015 at 2:54 pm #214184
this is a continuation of an earlier topic from a few weeks ago.
the situation is this: say a user goes to my HP, then clicks the Cart icon, then clicks on the Return to Shop box.
I want the user to return to the HP, and not be sent the WooCommerce Shop page, which is the default behavior.here is the relevant Atelier HTML
<a class="button wc-backward" href="https://needlepoint.land/index.php/catalog-2/">Return To Shop</a>
I wrote a JS function that should work. This code has been examined by other programmers on Stackoverflow. This function was tested in other environments and it worked fine there. But it does not execute correctly on WP/Woocommerce/Atelier using O, FF, or Chrome.
Can anyone at Swiftideas tell me if they know of something (some Atelier listener, for instance) that may be sitting on the server side and preventing/blocking the referrer string (or even a harcoded URL, which I also attempted to use as a redirect) from being assigned to the a element’s href?
Is this an Atelier issue? Or is this some sort of browser sandbox thing?
I may have to go to WP.org forums for further insight into solving this problem, but I thought I would first ask Swiftideas support for guidance.
Here is the code (as you can see, I attempted several methods to perform the redirect):
window.onload = function () { document.querySelector(".button.wc-backward").onclick = function() { // query selector works as expected var URLstring = document.referrer; // works fine window.location.assign(URLstring); // blocked window.location.href = URLstring; // href unchanged, blocked setTimeout(function () { window.location.href = URLstring; },100); // blocked, even with delay return false; // does not cancel default behavior } }
Thanks as always for any help you can provide.
September 17, 2015 at 3:06 pm #214189This reply has been marked as private.September 17, 2015 at 3:12 pm #214193Hi,
I need to login to check in detail.
Thanks
MohammadSeptember 17, 2015 at 3:25 pm #214200Hi,
If you use the Chrome web dev tools, do you also see the JS error?
Uncaught TypeError: Cannot set property 'onclick' of null
This is a very quick example of how I would do it with jQuery, though I would recommend you use PHP.
jQuery(document).ready(function() { var referrer = document.referrer; var defaultURL = 'http://google.com/cart'; 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."); } });
All the best,
David.September 17, 2015 at 3:39 pm #214211This reply has been marked as private.September 17, 2015 at 3:43 pm #214212@alibey, have you tried the jQuery I provided? That works as required for me on my dev version.
– David.
September 17, 2015 at 3:43 pm #214213This reply has been marked as private.September 17, 2015 at 3:47 pm #214214> david, amendation, that was the error i was getting, until i got the css syntax right in the queryselector (no space between the classes fixed the problem). now chrome does not complain about anything and queryselector is working correctly as i am testing everything in the chrome console. but the href redirect is being blocked by something.
September 17, 2015 at 3:52 pm #214217Seems to be work now with the supplied jQuery. #214200.
– David
September 17, 2015 at 3:55 pm #214218> david jquery code not working. not sure why google.com/cart is specified as the default url.
i know this may be old school, but it would be great to achieve this with plain old js. 😉
September 17, 2015 at 4:00 pm #214223jquery snippet chrome local scope watch
Local
<return>: undefined
defaultURL: “http://google.com/cart”
referrer: “https://needlepoint.land/”September 17, 2015 at 4:05 pm #214224Hi,
That was a for you to change to your default cart URL of your choice.
http://google.com/cart
It was a place holder.I supplied you with a solution for how I would do it, which works. It changes the link to the referring URL if set, if not it defaults to the default URL variable
defaultURL
.Thanks,
David.September 17, 2015 at 4:05 pm #214225all right i am going to pose the question to the regular wp.org forum
there must be something performing the redirect blocking, and i will be darned if i don’t find out what it is! thx for the help thoSeptember 17, 2015 at 4:06 pm #214226> david k. i see. will change default accordingly and see what happens. thanks again!
September 17, 2015 at 4:07 pm #214227Not sure why you cannot use the supplied jQuery?
– David.
-
Posted in: Atelier
You must be logged in and have valid license to reply to this topic.