-3

I have this page:

link

pass:dizi

I tried to make a redirection using this code:

CODE JQUERY:

var url = "http://dizievents.ch/index.php/event/food-n-liquor-dizinvolta-2/";
$(location).attr('href',url);

On firefox it seems that everything is ok but Chrome is continually refresh the page give.

What I think is that we enter into a infinite while loop.

I do not realize why this happens ... all the examples we have found are with this code.

Can you tell me please what would be the solution to this problem? You can test the site to see what happens on Chrome

Thanks in advance!

EDIT:

I tried so

var url = "http://dizievents.ch/index.php/event/food-n-liquor-dizinvolta-2/";
window.location.href = url;
Cristi
  • 61
  • 1
  • 5

3 Answers3

1

if, as soon as the page loads, you redirect to it again, it will keep reloading.

That javascript will run each time, and it will constantly redirect.

nycynik
  • 7,371
  • 8
  • 62
  • 87
0

Try this instead of the $(location)...

window.location.href = url;
brso05
  • 13,142
  • 2
  • 21
  • 40
Julia Will
  • 616
  • 3
  • 8
0

You can do like this:

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var temp = getParameterByName("dontredirect");
if(temp != "true")
{
    var url = "http://dizievents.ch/index.php/event/food-n-liquor-dizinvolta-2/?dontredirect=true";
    $(location).attr('href',url);
}

This will only redirect the first time visited. But we might be able to provide a better answer if you tell us why you want to redirect in the first place...

getParametersByName() taken from here

Community
  • 1
  • 1
brso05
  • 13,142
  • 2
  • 21
  • 40