Search code examples
javascriptshopifyredirect-loop

Can some one tell me how to make the function run once and then end?


I'm a total newb when it comes to stack please forgive me I have googled over and over and read several threads on stack on how others stopped a redirect loop however, the issue I have from what I have read is I need this page to redirect to same URL + /universal which as I understand is the reason for the loop. I tried the code for checking the url but it did not stop the loop.

$(window).load(function() {
url = "{{ collection.url }}/universal";
$( location ).attr("href", url);
});

Solution

  • I would make an if-statement and check if the URL already contains the "/universal" part, something like

    if(window.location.href.indexOf('/universal') < 0){
        url = "{{ collection.url }}/universal";
        $( location ).attr("href", url);
    }