2013-01-02 26 views
0

我在下面顯示的代碼只是示例,不工作,以查看您是否可以幫助實現目標命名約定。我似乎無法看到 瞭解你如何命名目標。實際的代碼很好地在頁面上創建了一個tabset,我試圖做的只有 給定選項卡上的click事件打開了與所選標籤對應的tab頁中所需的URL。看起來好像 這麼簡單,但是我沒有試過目標(包括_parent,_self等)的作品,我找不到任何有關 命名約定如何用於文檔中特定目標位置的示例。open.window的目標名稱是tabpage_1?

<!DOCTYPE html> 
<html> 
<head> 
<title>Networks</title> 
    <script> 
    function open_tp1() 
     { 
     window.open("http://www.ficticious1.com","#tabpage_1") //What is the target name to use insead of #tabpage_1 
    } 
    function open_tp2() 
    { 
     window.open("http://www.ficticious2.com","#tabpage_2") //What is the target name to use insead of #tabpage_2 
    } 
    </script> 
</head> 
<body> 
    <script src="tabs-soc.js"></script> 
    <form id="form1" name="form1"> 
    <div id="wrapper" style="width: 934px"> 
     <div id="tabContainer" style="width: 903px"> 
     <div id="tabs"> 
     <ul> 
      <li id="tabHeader_1"> 
      <img src="image1.png" alt="Image1" onclick="open_tp1()" /></li> 
      <li id="tabHeader_2"> 
      <img src="image2.png" alt="Image2" onclick="open_tp2()" /></li> 
     </ul> 
     </div> 
     <div id="tabscontent"> 
      <div class="tabpage" id="tabpage_1"> 

      </div> 
      <div class="tabpage" id="tabpage_2"> 

      </div> 
     </div> 
     </div> 
    </div> 
    </form> 
</body> 
</html> 
+0

這不是'window.open'的工作方式。你可能想要一個iframe。 – SLaks

+0

很難確定你的意思是「標籤」。顯然你的意思是「div」?瀏覽器選項卡不是出現在HTML頁面中的東西。 – LarsH

回答

1

您不能定位HTML元素,只能定位一個框架或一個窗口。 window.open只允許你定位一個窗口。

如果你想更換一個HTML元素的內容,那麼你必須使用JavaScript(例如,通過XMLHttpRequest)來獲取數據,然後manipulate the DOM將其插入到頁面中。

由於您在不同域使用絕對URI,因此您將受到same origin policy的約束,因此您需要使用其中一個workarounds

或者,忘記使用JavaScript並將an iframe放在文檔中。然後通過鏈接上的target attribute作爲目標。

+0

謝謝你的幫助。我插入了一個名爲id的id,id是I1。我已經將href插入到期望的.com中,並且target =「I1」。當我點擊href時,屏幕底部顯示正在等待所需的.com,然後任何地方都不顯示任何內容。 I1是否適合目標,還是需要更多像document.I1一樣,正如我在開始時所說的那樣,我無法弄清楚內部窗體位置的命名約定。 @Quentin – Robert