It looks like the chrome browser uses onload/windows.onload like document.onload (see: window.onload vs document.onload )
This leads to the problem that chrome reloads the page too early and for that reason I have a loop on my page. Firefox and IE don't have this problem.
I have the following code to create a cookie (it is not my own code, it is from a software called 'Post Affiliate Pro'):
<script type="text/javascript">
<!--
document.write(unescape("%3Cscript id='pap_x6hetgh' src='" + (("https:" == document.location.protocol) ? "https://" : "http://") +
"www.example.com/papscript/scripts/trackjs.js' type='text/javascript'%3E%3C/script%3E"));//-->
</script>
I have to reload the page thats why I use the following code (I reduced the checkCookie code a little bit for better reading):
<script>
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function checkCookie() {
var user = getCookie("PAP");
if (user != "") {
}
else {
window.location.reload();
}
}
</script>
<body onload="checkCookie();">
I am looking for an idea how to solve the problem. With the onload-problem on chrome.