javascript自毁网页

时间:2014-05-15 18:58:18

标签: javascript jquery html 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()

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>

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>

1 个答案:

答案 0 :(得分:5)

这应该是一个提供信息的答案:why doesn't my window.close work

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