Change a link's destination

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JasonP27
    New Member
    • Jun 2008
    • 2

    #1

    Change a link's destination

    I want to change the href destination of a link, based upon the page title or document's filename of an iframe.

    For example: If the TITLE of the iframe is Poem1, or the document loaded in the iframe is poem1.html, then I want the "Next" link (on the main page) to point to poem2.html

    [HTML]<html>
    <head>
    <title>Poem1</title>
    </head>
    <body>
    <a href="poems/poem2.html" id="link1">Next </a><p></p>
    <iframe name="inline1" src="poems/poem1.html">
    </iframe>
    </body>
    </html>[/HTML]
    But that is not all... I will have an indefinite amount of pages with filenames like so poem[#].html starting with poem1.html, poem2.html, poem3.html

    I want to just be able to tell the link to change the href to the next numbered page. If on page poem23, the Next link should change to go to poem24

    I have no idea what the syntax what I am doing

    [CODE=JavaScript (yeah, right)]
    document.link1. href == newLink

    newLink = (currentLink + 1 )
    currentLink = document.inline 1.src[/CODE]
    Do you understand how clueless I really am? I have no clue what I'm doing!

    Anyone?
    Last edited by JasonP27; Jun 5 '08, 05:48 AM. Reason: add HTML tags
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    That poem23.html will be string. To change it to poem24.html you need to split that into three parts first.
    "poem", "23", ".html".
    then you change the middle value to a number and add one to it. After that you simply put the pieces back together again.

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      yes ... another option would be to use regEx and the replace()-method for this ... have a look at the following example:

      [CODE=javascript]var l = 'poem23.html';
      var s = l.match(/(\d+)/)[1];
      l = l.replace(s, parseInt(s, 10) + 1);

      alert(l);
      [/CODE]
      kind regards

      Comment

      Working...