首先介紹兩個方法的語法:
reload 方法,該方法強迫瀏覽器刷新當前頁面。
語法:
location.reload([bForceGet])
參數: bForceGet, 可選參數, 默認爲 false,從客戶端緩存裏取當前頁。 true, 則以
GET 方式,從服務端取最新的頁面, 相當於客戶端點擊 F5("刷新")
replace 方法,該方法通過指定URL替換當前緩存在歷史裏(客戶端)的項目,因此當使用replace方法之後,你不能通過“前進”和“後退”來訪問已經被替換的URL。
語法:
location.replace(URL) 參數: URL
在實際應用的時候,重新刷新頁面的時候,我們通常使用: location.reload() 或者是 history.go(0) 來做。因爲這種做法就像是客戶端點F5刷新頁面,所以頁面的method="post"的時候,會出現“網頁過期”的提示。那是因爲Session的安全保護機制。可以想到: 當調用 location.reload() 方法的時候, aspx頁面此時在服務端內存裏已經存在, 因此必定是 IsPostback 的。如果有這種應用: 我們需要重新加載該頁面,也就是說我們期望頁面能夠在服務端重新被創建, 我們期望是 Not IsPostback 的。這裏,location.replace() 就可以完成此任務。被replace的頁面每次都在服務端重新生成。你可以這麼寫: location.replace(location.href)
=======================================================<a onclick="javascript:window.location.href=window.location.href;">
<a onclick="javascript:window.location.reload();">
測試效果一樣。表單沒有提交。
<input type="submit" onclick="javascript:window.location.reload();" value="單擊" id="btnVCode" />
<input type="submit" onclick="javascript:window.location.href=window.location.href;" value="單擊" id="btnVCode" />
都提交數據
window.location.Reload()應該是刷新.(如果有數據提交的話,會提示是否提交的(是和否選項))
window.location.href=window.location.href; 是定向url提交數據
最好不要用location.reload(),而用location=location比較好,還有在模式窗口(showModalDialog和showModelessDialog)前者不能用。
reload參數有true和false,比較有意思?
避免重複提交:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string nr = ((DataRowView)e.Item.DataItem).Row["GZZDS"].ToString();
string id = ((DataRowView)e.Item.DataItem).Row["RZID"].ToString();
string rid = ((DataRowView)e.Item.DataItem).Row["RWXH"].ToString();
string link = "";
if (nr == "")
{
link = "<a href='#' onclick=\"selectGuide2('BookDoc.aspx?type=2&Id=" + id + "&rid=" + rid + "&Rnd='+Math.random());location=location;\">選擇指導書</a>";
}
else
{
string t = (ViewState["State"].ToString() == "Query" || ((DataRowView)e.Item.DataItem).Row["GZZT"].ToString() == "工作結束") ? "false" : "true";
string path=((DataRowView)e.Item.DataItem).Row["GZZDSPath"].ToString();
link = "<a href='#' onclick=\"EditWord('" + path + "'," + t + ")\">" + nr + "</a>";
}
((Literal)e.Item.FindControl("Literal1")).Text = link;
}
}
window.location.Reload()和window.location.href window.location.Reload()應該是刷新.(如果有數據提交的話,會提示是否提交的(是和否選項))
window.location.href=window.location.href;
是定向url提交數據
是大的區別還是是否提交數據了
function refresh()
{
//刷新頁面函數
//window.focus();刷新窗口
//document.execCommand("Refresh");刷新窗口
//self.location.reload();刷新當前窗口
parent.location.reload();刷新父窗口
//aaa.location.reload();彈出窗口刷新父窗口
}
使用window.location.replace() or window.location.href(), 來重新加載此頁面不出現提示框