开发者

Javascript event never triggering

I am working on a signup for the mailing list and an trying to make the page and js file not be cached by the browser. Thus, I use a f开发者_开发百科ake query string. I am trying to get the page to make a new query string when it is refreshed. It doesn't work... why? I think the line:

window.onbeforeunload=changeNoCache();

is in the wrong place.

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Email Sign-Up</title>
<link href="SignUp.css" rel="stylesheet" type="text/css" />
<script id="script" type="text/javascript" src="SignUp.js"></script>
<script type="text/javascript">
function noCache() {
    regex=/noCache/;
    if (!regex.test(window.location.href)) {
        rand=getRandom();
        window.location.href+="?noCache="+rand;
    }
    else {
        h=true;
    }
    if (!regex.test(document.getElementById("script").src)) {
        rand=getRandom();
        document.getElementById("script").src+="?noCache="+rand;
    }
    else {
        s=true;
    }
    if (h&&s) {
        window.onbeforeunload=changeNoCache();
    }
}
function changeNoCache() {
    loc=window.location.href.indexOf("?");
    window.location.href=window.location.href.substring(0,loc);
    loc=document.getElementById("script").src.indexOf("?");
    document.getElementbyId("script").src=document.getElementById("script").src.substring(0,loc);
    noCache();
}
function getRandom() {
    rand=Math.random()+"";
    rand=rand.substring(0,15);
    rand=Number(rand);
    return rand;
}
</script>
</head>
<body onLoad="noCache();">
Email Address: <input type="email" id="email" />
<button onClick="makePopUp();">Submit</button>
</body>
</html>

SignUp.js:

function makePopUp() {
    div = document.getElementById("shell");
    if(!div) {
        email = document.getElementById("email").value;
        popupshell = document.createElement("div");
        popupinner = document.createElement("div");
        popupshell.id = "shell";
        popupinner.id = "inner";
        popupinner.innerHTML = "<span id=\"closebutton\" onClick=\"closePopUp();\">x</span><div id=\"form\">Thank You. Would you like to enter other information so that we can make your emails more relevant? If so, enter your information below. Otherwise, you may click the x button in the top right of this window to close it.<br /><br /><form name=\"Email Signup\" action=\"sql_submit.php\" method=\"post\"><input type=\"hidden\" value=\"Email Signup\" name=\"formname\" /><input type=\"hidden\" value=\""+window.location+"\" name=\"url\" />Email: <input name=\"email\" type=\"text\" value=\""+email+"\" /><br />First Name: <input type=\"text\" name=\"firstname\" /><br />Last Name: <input type=\"text\" name=\"lastname\" /><br />Country Code: <input type=\"text\" name=\"countrycode\" id=\"countrycode\"  size=\"2\" onBlur=\"validatePhone();\" />Phone Number: <input type=\"text\" name=\"number\" id=\"number\" size=\"10\" onBlur=\"validatePhone();\" /><br />Company Name: <input type=\"text\" name=\"company\" /><br />Serial Number: <input type=\"text\" name=\"serial\" /><br /><br /><input type=\"submit\" value=\"Submit\" /></form></div>";
        popupshell.appendChild(popupinner);
        document.body.appendChild(popupshell);
    }
    else {
        blink(div);
        t = setTimeout("blink(div);",100);
        t = setTimeout("blink(div);",200);
        t = setTimeout("blink(div);",300);
        t = setTimeout("blink(div);",400);
        t = setTimeout("blink(div);",500);
    }
}
function blink(element) {
    (element.style.display=='none') ? element.style.display='block' : element.style.display='none';
}
function validatePhone() {
    cc = document.getElementById("countrycode");
    number = document.getElementById("number");
    cc.value = cc.value.replace(/\D/g,"");
    number.value = number.value.replace(/\D/g,"");
}
function closePopUp() {
    document.body.removeChild(document.getElementById("shell"));
}


ad this to your head section

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

The directive CACHE-CONTROL:NO-CACHE indicates cached information should not be used and instead requests should be forwarded to the origin server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜