View Full Version : Return False to Location Change
Guardian23
07-02-2002, 11:59 AM
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)
joh6nn
07-02-2002, 12:57 PM
or, what about:
<a href="javascript:function_name(); void 0;" target="_parent">link name</A>
Guardian23
07-02-2002, 01:02 PM
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
Guardian23
07-02-2002, 01:08 PM
joh6nn, yes, it worked, but I'm not overly familiar with the "void 0" property/attrib, what is it and what does it do?
joh6nn
07-02-2002, 01:23 PM
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.
Guardian23
07-02-2002, 01:30 PM
I see..... thanks for information, it helped a lot, cleared up the problem with the script too. :)
Guardian
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.