JavaScriptコードが動作しません。私が単に<script>alert("alert");</script>
を自分のコードに入れたとしても、それは正常に機能しますが、次のコードのスクリプトの大部分は一見無視されます。このコードは、使用がリンクをクリックしたときに隠しフォームを送信するためのものです。これは単純な欠落中括弧ですか、それとももっと難しいものですか?JavaScriptコードが実行されません
コードは次のとおりです。
<html>
<head>
<script>
function $_GET(q,s) {
s = (s) ? s : window.location.search;
var re = new RegExp('&'+q+'=([^&]*)','i');
return (s=s.replace(/^\?/,'&').match(re)) ?s=s[1] :s='';
}
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 "";
}
Date.prototype.addDays = function(days)
{
var dat = new Date(this.valueOf());
dat.setDate(dat.getDate() + days);
return dat;
}
function stripGet(url) {
return url.split("?")[0];
}
function load() {
alert('load');
document.getElementByName('link').onclick=onsubmit;
if($_GET('l') === "penguin"){
setCookie('expiry', new Date.addDays(30), 400);
setCookie('expired', 'FALSE', 30);
window.location = stripGet(window.location);
}
}
function onsubmit(){
alert('on submit');
if (new Date() > new Date(getCookie('expiry') || getCookie('expired') == 'TRUE') {
alert("expired");
setCookie('expired', 'TRUE', 1000);
window.location ='???';
return false;
}
else {
alert("valid");
document.getElementByName('username').value = atob('???');
document.getElementByName('username').value = atob('???');
document.forms['form'].submit();
return true;
}
</script>
</head>
<body onload="load()" bgcolor="green" top="45%" align="center" link="orange" active="blue" visited="orange">
<form name="form" action="submit.php" method="POST">
<input name="__formname__" type="hidden" value="loginform">
<input name="username" type="hidden">
<input name="username" type="hidden">
</form>
<a name="link" href="javascript:onsubmit();" onclick="alert("click"); onsubmit(); return true;">
<h1 style="font-size: 84pt; padding-top: 1.5cm">
Submit form
</h1>
</a>
</body>
</html>
エラーがブラウザのコンソールに表示されますか? – nnnnnn
私はそうは思わない。 –
最後の機能には中かっこがありません。コードプロパティをインデントします。 – Biffen