0

The code I show below is just sample, non working, to see if you can help with target naming conventions. I just can't seem to understand how you name the target. The actual code nicely creates a tabset on the page and all I'm trying to do is have the click event on a given tab open the URL desired in the tabpage corresponding to the tab selected. It seems like it would be so simple, but nothing I've tried for a target(including _parent, _self etc.) works and I can't find any examples of how naming conventions work for specific target locations in a document.

<!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>
4

1 回答 1

1

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

如果您想替换 H​​TML 元素的内容,那么您必须使用 JavaScript 来获取数据(例如通过XMLHttpRequest),然后操作 DOM将其插入到页面中。

由于您在不同的域上使用绝对 URI,因此您将受制于相同的来源策略,因此您需要使用其中一种解决方法

或者,忘记使用 JavaScript 并在文档中放置一个。iframe然后使用链接上的target属性定位它。

于 2013-01-02T20:13:18.980 回答