2014-10-10 27 views
0

球員我想知道你是否看到任何有關此代碼的內容會導致無限重定向。我無法弄清楚。這是使用正確加載的GeoIP2 API。由腳本導致的無限重定向

var redirect = (function() { 
    var onSuccess = function (geoipResponse) { 
    var sites = { 
     "cn": true 
    }; 

    if (!geoipResponse.country.iso_code) { 
     window.location.replace("http://gotriplec.com/"); 
    } 

    var code = geoipResponse.country.iso_code.toLowerCase(); 

    if (sites[code]) { 
     alert("Your IP cannot access this website... We apologize for any inconvenience caused."); 
     window.location.replace("http://www.google.com"); 
    } 

    else { 
     window.location.replace("http://gotriplec.com/"); 
    } 
    }; 

    var onError = function (error) { 
    window.location.replace("http://gotriplec.com/"); 
    }; 

    return function() { 
    geoip2.country(onSuccess, onError); 
    }; 
}()); 

回答

0

不看代碼的其他部位,不能告訴太多,但如果你的網站是「http://gotriplec.com/」和你打電話redirect()在頁面加載/準備這個頁面上,那種情況下會導致無限重定向。

+0

Ahhh我通過閱讀您的消息來看問題。每個登錄名都有window.location.replace。如果我只留下適當的重定向,它應該工作.... – 2014-10-10 03:19:38