2012-08-28 35 views
0

多個站點,我試圖讓這樣的事情: Example的iFrame從下拉

我希望能夠動態更改過的下拉列表中選擇的選項的iframe中。

我到目前爲止的代碼是這樣的:

<html> 
    <head> 
    <script> 
     function hidem() { 
     document.getElementById('Select').style.display = "none"; 
     document.getElementById('test1').style.display = "none"; 
     document.getElementById('test2').style.display = "none"; 
     } 
    function changeIt(divid) { 
     hidem(); 
     document.getElementById(divid).style.display = "block"; 
    } 
    </script> 
    </head> 

    <table border="0"> 
     <tr> 
      <td> 
       <select id="Manage" onChange="changeIt(this.value)"> 
       <option value="Select">Select A Management Window</option> 
       <option value="test1">Google</option> 
       <option value="test2">Yahoo</option> 
       </select> 
      </td> 
      <td> 
       <div id="Select"> 
        <h2>Information:</h2> 
        This is a management console 
       </div> 
       <div id="test1" style="display:none"> 
        <h2>Google:</h2> 
        <iframe src="http://www.google.com" width="100%" height="100%"></iframe> 
       </div> 
       <div id="test2" style="display:none"> 
      <h2>Yahoo:</h2> 
        <iframe src="http://www.yahoo.com" width="100%" height="100%"></iframe> 
       </div> 
      </td> 
     </tr> 
    </html> 

,但它似乎沒有工作,我希望的方式。任何人都可以幫助我解決這個問題?

謝謝你,

戴夫

+0

你的HTML是相當搞砸的列表。沒有BODY標籤,沒有FORM標籤,沒有關閉TABLE標籤。你也不應該使用表格來做這樣的HTML佈局。您應該只使用塊級元素,如DIV標籤等。 –

+0

您想如何「動態更改iframe」? –

+0

@EricLeschinski我希望能夠更改基於下拉項目加載的網頁。 – Dave

回答

0

儘管無效的HTML錯誤(已在由@BillyMoat的評論從未被高亮顯示)的數量巨大,我不相信你就可以做你正在策劃。

許多大型網站(特別是谷歌)在其網頁上使用X-Frame-Options: SAMEORIGIN

這意味着瀏覽器不允許在其父母來自不同來源(即域)的框架中顯示該頁面......當然,這取決於瀏覽器瞭解該指令,這是目前大多數瀏覽器所做的。

Details of the header from Mozilla

Here is a blog listing more details about the header,包括瀏覽器,這將阻止加載頁面