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>
Robert
  • 29
  • 1
  • 1
  • 2
  • That's not how `window.open` works. You may want an iframe. – SLaks Jan 02 '13 at 20:12
  • Hard to be sure what you mean by "tab". Apparently you mean "div"? A browser tab is not something that appears within an HTML page. – LarsH Jan 02 '13 at 20:15

1 Answers1

1

You can't target an HTML element, only a frame or a window. window.open only allows you to target a window.

If you want to replace the content of an HTML element then you must use JavaScript to fetch the data (e.g. via XMLHttpRequest) and then manipulate the DOM to insert it into the page.

Since you are using absolute URIs on different domains, you will be subject to the same origin policy so you will need to use one of the workarounds for that.

Alternatively, forget about using JavaScript and place an iframe in the document. Then target that with the target attribute on a link.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thank you for help. I have inserted an iframe named and id are I1. I have inserted an href to desired .com with target="I1". When I click on href the bottom of screen says waiting for desired .com and then nothing is displayed anywhere. Is I1 appropriate target or does it need more like document.I1 as I said at beginning of this I can't figure out naming convention for internal locations of form. @Quentin – Robert Jan 02 '13 at 21:25