Web Analytics Made Easy -
StatCounter multiple links targeting iframe - CodingForum

Announcement

Collapse
No announcement yet.

multiple links targeting iframe

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • multiple links targeting iframe

    Hi,

    Done a search and I couldn't find anything that matches, hope someone can help.

    I have say 3 urls and an iframe on index.html

    var url1 = page1.html
    var url2 = page2.html
    var url3 = page3.html

    <iframe src="page.html" name="links"></iframe>

    I then have 2 links

    <a href="javascript:next()">Next</a> | <a href="javascriptrev();>previous</a>

    When I click next I want the iframe to change to page1.html and when I click it again I want it to go to page2.html, same if the previous was clicked it would go back to page1.html.

    All this without refreshing the index.html page the Next and Previous links are on.

    Hope I explained that easy enough,

    thanks in advanced

    Death = $Mill

  • #2
    Node the following is code directly in the forum and therefore untested.,

    <script>
    var urls =new Array('page.html','page1.html','page2.html','page3.html');
    I=0;
    function next()
    {
    I+=1;
    if(I==urls.length)I=0;
    window.frames['links'].location.href=urls[I];
    }
    function prev()
    {
    I-=1;
    if(I==-1)I=urls.length-1;
    window.frames['links'].location.href=urls[I];
    }
    </script>


    <iframe src="page.html" name="links"></iframe>

    <a href="javascript:next()">Next</a> | <a href="javascriptrev();>previous</a>

    Comment


    • #3
      multiple links targeting iframe - update

      Hi,

      I've updated the script to try and load different text into a DIV with each next and previous but its not having any of it.

      What am I doing wrong?

      Thanks,

      Death = $Mill

      <script language="JavaScript">
      <!--

      ns4 = (document.layers)? true:false;
      ie4 = (document.all)? true:false;

      var urls = new Array('page1.html','page2.html','page3.html');

      var text = new Array('you are on page 1','yo page 2','hehehe page 3');

      I=0;
      function next(id)
      {
      I+=1;
      if(I==urls.length)I=0;
      window.frames['links'].location.href=urls[I];

      if (ns4) {
      var obj = document.layers[id].document;
      obj.open();
      obj.write(text);
      obj.close();
      }
      if (ie4) document.all[id].innerHTML = text
      }

      function prev(id)
      {
      I-=1;
      if(I==-1)I=urls.length-1;
      window.frames['links'].location.href=urls[I];

      if (ns4) {
      var obj = document.layers[id].document;
      obj.open();
      obj.write(text);
      obj.close();
      }
      if (ie4) document.all[id].innerHTML = text
      }


      //-->
      </script>
      <DIV ID="RWme">What page you on Son?</DIV>
      <P>
      <iframe src="page1" name="links" width="130" height="100"></iframe>
      <P>
      <a href="javascriptrev('RWme');">Previous</a> | <a href="javascript:next('RWme')">Next</a>

      Comment


      • #4
        dude omg thank you so much this solved my problem btw the
        <a href="javascriptrev();"> should be <a href="javascriptrev();"> that should help you lol

        Comment

        Working...
        X