Ad

Can Some One Tell Me How To Make The Function Run Once And Then End?

- 1 answer

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);
});
Ad

Answer

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);
}
Ad
source: stackoverflow.com
Ad