2012-06-02 120 views
0

我確定知道有人對我遇到的這個問題有解決方案嗎?我有一個包含Iframe的Index.html網站。在此iframe中,該網站的所有頁面均顯示... Home.html..Info.html ... Contact.html..etc。在父框架中打開iframe頁面(javascript)

我想要一個JavaScript函數,以便當您通過google sitemap打開Home.html時,它會顯示在Index.html的父框架中。我目前在每個子頁頭部分的功能是:

<script> if (parent.location.href == self.location.href){ window.location.href = 'index.html' } </script>

雖然這個工作,它不記得孩子頁面,並使用默認的iframe頁面...首頁打開索引頁作爲html的iframe的編碼是這樣的:

<iframe id="iframe" src="home.html" allowTransparency="true" id="iframeID" name="iframeID" width="100" height="100" scrolling="no" frameborder="no"> </iframe>

有沒有人解決這個問題,因爲我已經找遍?謝謝。

回答

1

嘗試設置與location.href查詢字符串,即:

// .getAttribute so we don't get the absolute URL 
var src = document.getElementById("iframe").getAttribute("src"); 
if (parent.location.href === self.location.href) 
    location.href = "index.html?" + escape(src); 

index.html中創建查詢字符串進行檢查,並設置相應的iframe來源:

if (location.search) 
    document.getElementById("iframe").src = 
      unescape(location.search.substring(1)); 
+0

@ MaxArt謝謝您回覆,我敢肯定,這是沿着這些線路,但作爲一個「新手」的JavaScript我似乎無法弄清楚。我的iframe ID是「iframeID」,因此大概必須在您給我的代碼中進行更改,但是我還要修改哪些內容?任何幫助深表感謝。 – RoadRunner

+0

@RoadRunner其實,*你*在你的文章中寫了'id =「iframe」',我只是用它......我不知道還有什麼要修復的,因爲我不知道你的頁面的其他部分和代碼。 – MaxArt

+0

正確,我的歉意,它錯誤地寫在代碼兩次。仍然沒有運氣,我害怕..如果有幫助,整個網站在euromodels.fr上線?謝謝 – RoadRunner

相關問題