Web Analytics Made Easy -
StatCounter Return False to Location Change - CodingForum

Announcement

Collapse
No announcement yet.

Return False to Location Change

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

  • Return False to Location Change

    I need some help, can someone tell me how to return false to a window location change? I tried using the below code, because I want to run a function at the same time and would prefer it being treated as a link rather than text(more distinguishable).

    <A HREF="" TARGET=_PARENT onclick="(window.location='');return false;function_name()">link name</A>
    (note:href is empty, window.location is too)

  • #2
    or, what about:

    <a href="javascript:function_name(); void 0;" target="_parent">link name</A>
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment


    • #3
      Thanks Dave, it worked! So 'return false' being placed at the end doesn't return false to the function call? Just the location change?

      Guardian
      Last edited by Guardian23; Jul 2, 2002, 08:05 AM.

      Comment


      • #4
        joh6nn, yes, it worked, but I'm not overly familiar with the "void 0" property/attrib, what is it and what does it do?

        Comment


        • #5
          the 'void' operator voids anything that comes after it. when you use a HREF="javascript:" link, the browser use the value, that the last line of javascript returned, as the url it should go to. so, if you use just a javascript:something(); link, you'll get a new page, that has the value that something() returned. by including a line after it, that has essentially no value (void actually returns null, or undefined, i forget which), the browser remains at the current page, because it has nowhere to go.

          as for Dave's example, if you include return false at the end of an event handler, like OnClick, it will cancel the default action of that event. So including it at the end of an OnClick event for a link, will keep the browser from changing locations. any javascript that comes before it, will still be executed.
          bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

          i am a loser geek, crazy with an evil streak,
          yes i do believe there is a violent thing inside of me.

          Comment


          • #6
            I see..... thanks for information, it helped a lot, cleared up the problem with the script too.

            Guardian

            Comment

            Working...
            X