新标签超时功能
Timeout function for new tab
我用密码保护了一个 link,它将在新标签页中打开,但我现在希望该标签页在片刻后超时。我已经试过了,但无济于事,任何帮助都会很棒!
<script>
var newWin;
function validatePass(){
if(document.getElementById('password').value == 'Techsoc'){
newWin = window.open('https://docs.google.com/spreadsheets/d/e/2PACX-1vRsNGb741vTBtSGlzbxnTsoZpFMs0l9ZMrD54uE4XGy6FvSMmNfp3RPWvDU3vI32iSIp07CEshGLo0M/pubhtml');
}else{
alert('Incorrect Password, please try again.');
return false;
setTimeout(function(){newWin.close()}, 5000);
}
}
</script>
问题是在 else 语句中超时,而在 if 中创建了新的 window。现在,如果您输入密码并单击按钮,它应该会打开新选项卡并在超时设置的时间后关闭。
<input type="password" id="password"></input>
<button OnClick="validatePass()">Log In</button>
<script>
var newWin;
function validatePass() {
if (document.getElementById('password').value == 'Techsoc') {
newWin = window.open('https://docs.google.com/spreadsheets/d/e/2PACX-1vRsNGb741vTBtSGlzbxnTsoZpFMs0l9ZMrD54uE4XGy6FvSMmNfp3RPWvDU3vI32iSIp07CEshGLo0M/pubhtml');
setTimeout(
function () {
newWin.close()
}, 5000);
}
else {
alert('Incorrect Password, please try again.');
return false;
}
}
</script>
我用密码保护了一个 link,它将在新标签页中打开,但我现在希望该标签页在片刻后超时。我已经试过了,但无济于事,任何帮助都会很棒!
<script>
var newWin;
function validatePass(){
if(document.getElementById('password').value == 'Techsoc'){
newWin = window.open('https://docs.google.com/spreadsheets/d/e/2PACX-1vRsNGb741vTBtSGlzbxnTsoZpFMs0l9ZMrD54uE4XGy6FvSMmNfp3RPWvDU3vI32iSIp07CEshGLo0M/pubhtml');
}else{
alert('Incorrect Password, please try again.');
return false;
setTimeout(function(){newWin.close()}, 5000);
}
}
</script>
问题是在 else 语句中超时,而在 if 中创建了新的 window。现在,如果您输入密码并单击按钮,它应该会打开新选项卡并在超时设置的时间后关闭。
<input type="password" id="password"></input>
<button OnClick="validatePass()">Log In</button>
<script>
var newWin;
function validatePass() {
if (document.getElementById('password').value == 'Techsoc') {
newWin = window.open('https://docs.google.com/spreadsheets/d/e/2PACX-1vRsNGb741vTBtSGlzbxnTsoZpFMs0l9ZMrD54uE4XGy6FvSMmNfp3RPWvDU3vI32iSIp07CEshGLo0M/pubhtml');
setTimeout(
function () {
newWin.close()
}, 5000);
}
else {
alert('Incorrect Password, please try again.');
return false;
}
}
</script>