2012-08-08 43 views
0

在以下網站運行(http://www.homefresh.co.nz/gallery.html)有一塊的JavaScript了頂級的動態改變我的iFrame的Javascript不在現場

Javascript語言,標題的高度:

<script type="text/javascript" language="javascript"> 
<!-- 
function calcHeight() 
{ 
    //find the height of the internal page 
    var the_height=document.getElementById('the_iframe').contentWindow.document.body.scrollHeight; 
    //change the height of the iframe 
    var the_height = parseFloat(the_height) + 15; 
    document.getElementById('the_iframe').height=the_height; 
} 
//--> 
</script> 

,並在頁面的IFRAME代碼:

<iframe src="http://www.dpdesignz.co.nz/homefresh/" id="the_iframe" onLoad="calcHeight();" height="1" width="920px" scrolling="auto" frameBorder="0"></iframe> 

除了一些原因,它沒有更新

我在這裏有完全相同的代碼,它的工作原理(http://www.dpdesignz.co.nz/homefresh/test.htm

任何人都可以看到阻止它的任何東西嗎?

+2

不安全的JavaScript嘗試從網址http://www.dpdesignz.co.nz/homefresh/訪問框架,網址爲http://www.homefresh.co.nz/gallery.html。域,協議和端口必須匹配。 gallery.html:192 Uncaught TypeError:無法讀取未定義的屬性'body'這是Chrome在打開資源標籤時所說的內容(按f12後 – 2012-08-08 09:02:51

+0

而Mozilla Firefox說:[11:03:32,838]錯誤:權限被拒絕訪問財產'文件'@ http://www.homefresh.co.nz/gallery.html:192。 – Ricola3D 2012-08-08 09:05:09

回答

3

帶腳本和iframe頁面的頁面必須位於同一個域中。由於安全問題,同樣需要Same origin policy

所以,如果你想訪問www.dpdesignz.co.nz上的文件,那麼你必須使用www.dpdesignz.co.nz域上的主機頁面。這就是爲什麼你的一個腳本可以工作,而另一個不可以。

+0

謝謝。是否有任何解決這個,你知道嗎? – dpDesignz 2012-08-08 10:14:57

+0

不,沒有與iframe ..你可以嘗試通過AJAX請求下載您的頁面並直接在您的網站上呈現,但這可能會使問題變得複雜而不是真正的幫助.. – 2012-08-08 11:53:55

+1

感謝您的回覆。 – dpDesignz 2012-08-09 05:57:48