javascript:history.go()和History.back()的區(qū)別

字號(hào):


    <input type=button value=刷新 onclick="window.location.reload()">
    <input type=button value=前進(jìn) onclick="window.history.go(1)">
    <input type=button value=后退 onclick="window.history.go(-1)">
    <input type=button value=前進(jìn) onclick="window.history.forward()">
    <input type=button value=后退 onclick="window.history.back()"> 后退+刷新<input type=button value=后退 onclick="window.history.go(-1);window.location.reload()">在C# Web程序中,如為頁(yè)面按鈕寫(xiě)返回上一頁(yè)代碼
    this.RegisterClientScriptBlock("E", "<script language=javascript>history.go(-2);</script>");
    其中,history.go(-2),要寫(xiě)為-2,因在按鈕事件觸發(fā)前,已刷新一次頁(yè)面,所以應(yīng)是-2。
    Response.Write("<script language=javascript>history.go(-2);</script>");
    此處也要寫(xiě)為“-2”。跟直接寫(xiě)腳本的有所不同。history.back()是會(huì)上一頁(yè)
    i=1
    history.go(i)去指定的某頁(yè)
    如果是history.go(0)那就是刷新這兩個(gè)屬于JS代碼,相當(dāng)于IE的前進(jìn)、后退功能。
    具體的用處就要看什么時(shí)候需要這個(gè)就用上。比如用戶(hù)注冊(cè)時(shí)的驗(yàn)證是后臺(tái)驗(yàn)證,不符合要求的時(shí)候就可以用這個(gè),可以最大限度保證用戶(hù)少重復(fù)輸入數(shù)據(jù)。
    例如:載入頁(yè)面:
    function onLoadPage(){
    if(event.srcElement.tagName=="SPAN"){
    oFrame=top.window.middle.frames[2];
    oTxt=event.srcElement.innerText;
    switch(oTxt){
    case "前 進(jìn)":
    oFrame.history.go(1);
    case "后 退":
    oFrame.history.back();
    case "刷 新":
    oFrame.location.reload();
    }
    }
    }
    打開(kāi)一個(gè)jsp頁(yè)面,肯定是用客戶(hù)端腳本進(jìn)行刷新了。
    Javascript刷新頁(yè)面的幾種方法:
    1 history.go(0)
    2 location.reload()
    3 location=location
    4 location.assign(location)
    5 document.execCommand('Refresh')
    6 window.navigate(location)
    7 location.replace(location)
    8 document.URL=location.href