js重新整理頁面

來源:互聯網
上載者:User

標籤:實際應用   button   ram   pen   文法   query   ssi   產生   back   

location.reload() 和 location.replace()的區別和應用:

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)

 

 

reload()方法舉例

例1,重新整理當前頁面

<script> window.location.reload(); </script>

例2,JS實現重新整理iframe的方法 
用iframe的name屬性定位 

<input type="button" name="Button" value="Button" onclick="document.frames(‘ifrmname‘).location.reload()"> 或 <input type="button" name="Button" value="Button" onclick="document.all.ifrmname.document.location.reload()">

例3,首先,定義一個iframe 

<iframe method="post" id ="IFrameName" src="aa.htm" ></iframe>

aa.htm頁面的內容: 

<input type ="button" value ="重新整理" onclick ="aa()"/> function aa() { (jquery中文網 www.jquerycn.cn 編輯整理)//parent.location.replace(parent.location.href);//伺服器端重新建立頁面 parent.document.location.reload();//相當於F5 //window.location.href(parent.location.href);//iframe內容重新導向 }

注意:
window.location.reload;
重新整理時如果提交資料的動作,則會出現對話方塊!

解決辦法:

window.location.href=window.location.href; window.location.reload;

重新整理父視窗:

window.opener.location.href=window.opener.location.href; window.opener.location.reload(); 

這種寫法不會顯示對話方塊。

js重新整理頁面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.