2013-06-23 26 views
1

我會嘗試再次解釋:目標的iframe內頁

我有我的index.html 3個圖像,單擊時我想分別指向ourmission.html,ourvalues.html和ourvision html的。 但是這3頁是位於頁面ourcompany.html一個iframe中,你可以看到如下:

<aside class="sidebar"> 
<h4>Our Company</h4> 
    <ul class="nav nav-list primary pull-bottom"> 
     <li><a href="contactus.html"target="conteudo">Contact Us</a></li> 
     <li><a href="ourmission.html" target="conteudo">Our Mission</a></li> 
     <li><a href="ourvalues.html" target="conteudo">Our Values</a></li> 
     <li><a href="ourvision.html"target="conteudo">Our Vision</a></li> 

</ul> 
</aside> 

<iframe src="contactus.html" frameborder='0' name="conteudo" width="700" height="700"> 
</iframe> 

我如何直接指向他們,所以頁面ourcompany.html將打開特定的iframe裝載。

+0

您可以編輯您擁有的iframe中的頁面嗎? – stackErr

+0

是的。如果需要,我可以編輯所有頁面。 –

+0

你是什麼意思的「目標」它的iframe? – stackErr

回答

2

我得到了解決添加以下代碼到頁面其中的IFRAME位於:

<script> 
window.onload = function loadIframe(){ 
if (location.search.length > 0){ 
url = unescape(location.search.substring(1)) 

window.frames["iframe-name"].location=url 
} 
} 
</script> 

並使用HREF爲:

<a href="iframe-page.html?specific-iframe.html"> 

非常感謝所有試圖幫助我的人。

1

如果我正確理解了你,這可能是一個可能的解決方案。 我假設你沒有與網站建立服務器。

在您的index.html,你的圖像鏈接需要進行修改,以這樣的:

<a href="ourcompany.html?link=ourmission"><img src="" /></a> 
<a href="ourcompany.html?link=ourvalues"><img src="" /></a> 
<a href="ourcompany.html?link=ourvision"><img src="" /></a> 

的通知的ourcompany.html鏈接後?link=someValue。這是一個GET請求,但您將使用它來在頁面之間傳遞數據。

現在在您的ourcompany.html頁面中,您需要獲取?link=之後發送的值。所以你需要添加一些Javascript。這就是你需要添加到ourcompany.html功能:

function getValue() 
{ 
    // First, we load the URL into a variable 
    var url = window.location.href; 

    // Next, split the url by the ? 
    var qparts = url.split("?"); 

    // Check that there is a querystring, return "" if not 
    if (qparts.length == 0) 
    { 
    return ""; 
    } 

    // Then find the querystring, everything after the ? 
    var query = qparts[1]; 

    // Initialize the value with "" as default 
    var value = ""; 

    var parts = query.split("="); 

    // Load value into variable 
    value = parts[1]; 

    // Convert escape code 
    value = unescape(value); 

    // Return the value 
    return value; 
} 

現在,您可以相應地改變IFRAME src屬性是這樣的:

var link = getValue(); 
if (link.length){//check if you got a value 
    document.getElementByName('conteudo').src = link + ".html";//set the src 
} 
+0

它沒有工作。在地址欄中顯示正確的地址(即:'ourcompany.html?link = ourmission'),但仍然加載默認的iframe。 –