Executing function when <link> navigation element is used

Discussion in 'Javascript' started by Spartanicus, Nov 16, 2006.

  1. Spartanicus

    Spartanicus Guest

    I'd like to execute a function when a <link rel="next" href="foo.htm">
    type element is used. Although the "onclick" handler is allowed on the
    element, presumably because the functionality of the element is made
    available through a browser provided navbar the function doesn't execute
    when using the element.

    Anyone know if this is possible?

    --
    Spartanicus
     
    Spartanicus, Nov 16, 2006
    #1
    1. Advertising

  2. Spartanicus

    Randy Webb Guest

    Spartanicus said the following on 11/16/2006 3:40 PM:
    > I'd like to execute a function when a <link rel="next" href="foo.htm">
    > type element is used. Although the "onclick" handler is allowed on the
    > element, presumably because the functionality of the element is made
    > available through a browser provided navbar the function doesn't execute
    > when using the element.
    >
    > Anyone know if this is possible?


    Never done anything with a navbar but you might try setting the
    href="javascript:functionName()"

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Nov 16, 2006
    #2
    1. Advertising

  3. Spartanicus

    ASM Guest

    Spartanicus a écrit :
    > I'd like to execute a function when a <link rel="next" href="foo.htm">
    > type element is used. Although the "onclick" handler is allowed on the
    > element, presumably because the functionality of the element is made
    > available through a browser provided navbar the function doesn't execute
    > when using the element.



    onload = function() {
    var L = document.getElementsByTagName('link');
    var ok = false;
    for(var i=0; i<L.length; i++)
    if(L.href && L.href.indexOf('foo.htm')>0 &&
    L.rel && L.rel=='next') ok=true;
    if(ok) alert('right link');
    }

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Nov 16, 2006
    #3
  4. Spartanicus

    Spartanicus Guest

    Randy Webb <> wrote:

    >> I'd like to execute a function when a <link rel="next" href="foo.htm">
    >> type element is used. Although the "onclick" handler is allowed on the
    >> element, presumably because the functionality of the element is made
    >> available through a browser provided navbar the function doesn't execute
    >> when using the element.
    >>
    >> Anyone know if this is possible?

    >
    >Never done anything with a navbar but you might try setting the
    >href="javascript:functionName()"


    I need to preserve the href attribute value. I use JS to rewrite that
    value, but I don't want to make the feature JS dependant.

    --
    Spartanicus
     
    Spartanicus, Nov 17, 2006
    #4
  5. Spartanicus

    Spartanicus Guest

    ASM <> wrote:

    >> I'd like to execute a function when a <link rel="next" href="foo.htm">
    >> type element is used. Although the "onclick" handler is allowed on the
    >> element, presumably because the functionality of the element is made
    >> available through a browser provided navbar the function doesn't execute
    >> when using the element.

    >
    >onload = function() {
    >var L = document.getElementsByTagName('link');
    >var ok = false;
    >for(var i=0; i<L.length; i++)
    >if(L.href && L.href.indexOf('foo.htm')>0 &&
    > L.rel && L.rel=='next') ok=true;
    >if(ok) alert('right link');
    >}


    By "used" I meant "clicked", not present in the code.

    --
    Spartanicus
     
    Spartanicus, Nov 17, 2006
    #5
  6. Spartanicus

    ASM Guest

    Spartanicus a écrit :
    > ASM <> wrote:
    >
    >>> I'd like to execute a function when a <link rel="next" href="foo.htm">
    >>> type element is used. Although the "onclick" handler is allowed on the
    >>> element, presumably because the functionality of the element is made
    >>> available through a browser provided navbar the function doesn't execute
    >>> when using the element.

    >> onload = function() {
    >> var L = document.getElementsByTagName('link');
    >> var ok = false;
    >> for(var i=0; i<L.length; i++)
    >> if(L.href && L.href.indexOf('foo.htm')>0 &&
    >> L.rel && L.rel=='next') ok=true;
    >> if(ok) alert('right link');
    >> }

    >
    > By "used" I meant "clicked", not present in the code.


    How do you expect to click something not present ?

    <html>
    <script type="text/javascript">
    onload = function() {
    var L = document.getElementsByTagName('A');
    for(var i=0; i<L.length; i++)
    if(L.href && L.href.indexOf('foo.htm')>0 &&
    L.rel && L.rel=='next')
    L.onclick = function() {
    alert('Gasp! I am discovered');
    return false;}
    }
    </script>
    <a href="#">test 1</a>
    <a rel="next" href="foo.htm">foo</a>
    <a href="foo2.htm">test 1</a>
    </html>

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Nov 17, 2006
    #6
  7. Spartanicus

    Spartanicus Guest

    ASM <> wrote:

    >> By "used" I meant "clicked", not present in the code.

    >
    >How do you expect to click something not present ?


    That is the question I was asking. I'm not sure what phrase to use, not
    "used", not "clicked", "activated" would probably have been better.

    I am now experimenting with Randy's suggestion after I realised that I
    could use <link rel="next" href="foo.htm"> in the HTML and then rewrite
    the href value to "javascript:functionName()" with JS.

    --
    Spartanicus
     
    Spartanicus, Nov 17, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    882
    Kevin Spencer
    May 17, 2005
  2. Laurahn
    Replies:
    3
    Views:
    916
    Steven Cheng[MSFT]
    Feb 6, 2007
  3. VK
    Replies:
    8
    Views:
    513
    Joseph Kesselman
    Oct 31, 2006
  4. Rick
    Replies:
    1
    Views:
    2,215
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Jul 19, 2007
  5. HANM
    Replies:
    2
    Views:
    729
    Joseph Kesselman
    Jan 29, 2008
Loading...

Share This Page