javascript實現跨域重新整理

來源:互聯網
上載者:User

在XX項目裡面需要通過一個iframe去重新整理同一視窗的另外一個iframe。一個超級簡單的處理,但我還在blog上記一記,有些看似簡單的東西,在真實項目應用中還是值得思考地方

三個頁在同一個視窗,分別為main.htm,left.htm和right.htm。

main.htm

代碼

<html>
<head>
<title>實現跨</title>
</head>

<body>
<div>主視窗</div>

<iframe id="left" name="left" width="500px" height="300px;" src="left.htm" ></iframe>
<iframe id="right" name="right" width="100px" height="100px;" src="right.htm" ></iframe>

</body>

</html>

 

left.htm

<html>
<head><title>左邊</title></head>
<body>
<div>我是左邊</div>
<div><img src="http://www.enjoymyself.info/images/buysc.jpg" alt=" " /></div>
</body>
</html>

right.htm

代碼

<html>
<head><title>右邊</title></head>
<body>
<div>
<input onclick="onclickRefresh();" type="button" value="提交" /></div>
<script type="text/javascript">
function onclickRefresh()
{
parent.frames[ "left"].location.reload();
//window.left.location.reload();
}
</script>
</body>

</html>

看到right.htm裡面

function onclickRefresh()通過 parent.frames["left"].location.refresh();來實現右邊頁面重新整理左邊頁面.

如果在首頁面加

<div><input type="button" onclick="mainRefresh();" value="主提交" /></div>
<script type="text/javascript">
function mainRefresh()
{
window.left.location.reload();
}
</script>

則可以通過首頁面重新整理子頁面。

雖然這樣可以超級簡單的實現的目的,但是實際項目中,資料不會是這麼簡單的,最常見是左\右樹,分類樹的建立載入(如建立一千個節點)本來就是比較耗資源。如果還是通過方式來重新整理左右頁面,效率之低可見而知,那麼是不是可以通過其他方式來實現跨域重新整理或者提交呢?

我所想到的是通過ajax實現資料局部載入。而不是整個樹的載入。另外通過jquery的json處理方式也可實現局部資料的更新。

不知道還有沒有其他更高效的方法?1000個節點的樹載入,效率值得思考的問題。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.