follow a link ('soft')

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joris Gillis

    #1

    follow a link ('soft')

    Hi everyone,

    I have this nasty little problem to which I can't find a solution:

    Consider an anchor <a name="Top" id="Top">Top</a>

    How can I follow/execute this link from within javascript? In other words, how can I mimic the action that occurs when a user has clicked a (non-existing) <a href="#Top">cli ck me</a> link, so that the page will be shifted to the top (that's an example - not the actual goal)

    The link must be followed in the 'softest' possible manner: no opening of new window or page reloads/refreshes.

    something like: document.getEle mentById('Top') .follow()

    Any help is greatly appreciated.
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
    "Quot capita, tot sententiae" - Terentius , Phormio 454
  • RobG

    #2
    Re: follow a link ('soft')

    Joris Gillis wrote:[color=blue]
    > Hi everyone,
    >
    > I have this nasty little problem to which I can't find a solution:
    >
    > Consider an anchor <a name="Top" id="Top">Top</a>
    >
    > How can I follow/execute this link from within javascript? In other
    > words, how can I mimic the action that occurs when a user has clicked a
    > (non-existing) <a href="#Top">cli ck me</a> link, so that the page will
    > be shifted to the top (that's an example - not the actual goal)
    >
    > The link must be followed in the 'softest' possible manner: no opening
    > of new window or page reloads/refreshes.
    >
    > something like: document.getEle mentById('Top') .follow()[/color]

    The following script modifies the window.location to go to a
    specified anchor. The anchor does not have to be visible, it just
    has to exist.

    Note that you can't simply append the new anchor to the current URL,
    so the script removes any pattern matching #.* in the string of
    window.location , then adds the new anchor. This is a bit simplistic,
    you may need a more robust solution.

    I've wrapped lines to prevent autowrapping so the onclick looks a bit
    strange.


    <a href="#pageFoot " name="pageTop"> Normal anchor - go to foot</a>
    <br>
    <input type="button" value="JS function - go to foot" onclick="
    window.location =
    window.location .toString().rep lace(/\#.*/,'') + '#pageFoot';
    ">
    <br>
    <div style="position :absolute; top:2000px; border:1px solid blue;">
    <input type="button" value="JS function - go to top" onclick="
    window.location =
    window.location .toString().rep lace(/\#.*/,'') + '#pageTop';
    ">
    <br>
    <a name="pageFoot" href="#pageTop" >Normal anchor - to to top</a>
    </div>

    [color=blue]
    >
    > Any help is greatly appreciated.[/color]


    --
    Rob

    Comment

    • Martin Honnen

      #3
      Re: follow a link ('soft')



      Joris Gillis wrote:
      [color=blue]
      > I have this nasty little problem to which I can't find a solution:
      >
      > Consider an anchor <a name="Top" id="Top">Top</a>
      >
      > How can I follow/execute this link from within javascript?[/color]

      It is an anchor not a link but you can move to an anchor with
      window.location .hash = '#Top';

      --

      Martin Honnen
      http://JavaScript.FAQTs.com/

      Comment

      Working...