javascript自毁网页

Chr*_*s M 1 html javascript jquery redirect

我有一个倒计时的网页,并重定向到上一页,效果很好,但我想要关闭页面(当前浏览器选项卡),而不是重定向到上一页.消失.自毁.我试过替换我的重定向history.go(-1),window.close()但它没有用.

JS:

var countdownfrom=9    
var currentsecond=document.redirect.redirect2.value=countdownfrom+1

function countredirect(){
    if (currentsecond!=1){
    currentsecond-=1
    document.redirect.redirect2.value=currentsecond
    }
    else{
        history.go(-1)
    return
    }
    setTimeout("countredirect()",1000)
}    
countredirect()
Run Code Online (Sandbox Code Playgroud)

HTML:

<form name="redirect">
    <h1>Oops! &nbsp;I think you meant to use a URL...</h1>
    <h2>this page will self destruct in</h2>
    <form>
        <input type="text" size="1" name="redirect2">
    </form>
    <h2>seconds</h2>
    <h3>Go back to where you came from and try again!</h3>
Run Code Online (Sandbox Code Playgroud)

html看起来不正确,你甚至可以将表单嵌套在另一个表单中吗?它工作正常.

更正的HTML:

    <h1>Oops! &nbsp;I think you meant to use a URL...</h1>
    <h2>this page will self destruct in</h2>
    <form name="redirect">
        <input type="text" size="1" name="redirect2">
    </form>
    <h2>seconds</h2>
    <h3>Go back to where you came from and try again!</h3>
Run Code Online (Sandbox Code Playgroud)

The*_*Wes 5

这应该是一个信息丰富的答案:为什么我的window.close不起作用

长话短说,你可能不符合用JS关闭窗口的标准.