Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using href with onclick only

Status
Not open for further replies.

avivit

Technical User
Jul 5, 2000
456
IL
Hi,
I need to make links onclick and not using href,
i.e., I need:
<a href=&quot;#&quot; onclick=&quot;function(text)&quot;>
The function activated on clicking the link, is
opening a new window with the link, but when closing the new window or minoring it, it shows the opener page as
if I chose target to be top. I guess that's what href=&quot;#&quot;
does.
I want the page to stay scrolled as it was before choosing the link, and not moving to the top of the page.
Calling the function directly from the href is making me problems when using NS:
(<a href=&quot;javascript:function('text')&quot;>). It looks for the a page with the name of the function.
<a href=&quot;function('text')&quot;> is not good to NS as well.

<a href=&quot;javascript:void(0)&quot; is not good because I don't want &quot;javascript:void(0)&quot; to be shown on the status bar when clicking the link.

I tried it all(I hope not ALL), but found no answer.
Help anyone???
THANKS
 
<a name=&quot;no&quot; onclick=&quot;someFunc()&quot; href=&quot;#no&quot;>tok</a>

this isn't perfect, but might be better than what you had. You can also do something else:

function someFunc()
{
svpos=document.body.scrollTop;
shpos=document.body.scrollLeft;
setTimeout(&quot;scroll(shpos,svpos)&quot;,1)
//the rest of your code
}

this second thing only works in IE, sorry jared@aauser.com
 
<A href=&quot;javascript:function('text')&quot;> should work. If it is causing a problem, then the problem is probably internal to your function, not in how you call your function. I've always used this and it has always worked in NS and IE.

Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Hi avivit,

I agree with tanderso, <A href='javascript:function('text')&quot;> should work, i use it all the time.
but here is another way you can do.

<A href=&quot;javascript:void(0)&quot;
OnMouseOut=&quot;window.status=''; return true&quot;;
OnMouseOver=&quot;window.status=''; return true&quot;;>
OnClick=&quot;function('text')&quot;
</A>

by doing this, you won't see the &quot;javascript:void(0)&quot; shown on the status bar, and calling the function on the Onclick event.

hope this helps,



Chiu Chan
cchan@gefmus.com
 
jaredn:
1. The first solutionm is great. It IS perferct if I had few links. Why do you say it is not?
I'll have to name each link differently, with a loop. I have a list from database.

2.The 2nd option looks great.
My question is what shell I do with the <a href=&quot;#&quot;..>
If I still leave it as is, then this solution does not work,
so what shuld I write instead of the &quot;#&quot;?
Please DON'T tell me: &quot;javascript:void(0)&quot;.

Tom, I remeber never having problems with this before, so I guess u r right. It is part of asp page, written in vbscript,
maybe it has anything to do with it.
I'll check again and tell you what exactly doesn't worj then, maybe u'll know the reason better.
Thanks much, both
Avivit
 
PepperPepsi , Thanks alot for your time.
I already tried that (Actually I began with that) and
it's true there's no &quot;javascrupt:void(0)&quot; when the mouse is out/over. But on the time of CLICKING: thre is.
The status bar dos not show it for long time, because the
function (which opens a new window) is activated.
But I stil don't want it.
Anymore ideas?
Thanks again
 
put anchors and use them, so the ahref won't go to the top of the page <a href=&quot;yourpage.htm#middle_of_the_page&quot;>...
or use pepperpepsi idea's, and add again the same code for the onclick event !
 
iza. It sounds so simple from you. I'll try it of course.
 
i forgot to say, if you want to use the anchor stuff, don't forget to declare the anchor !! (that means that in yourpage.htm you have to add somewhere : <a name=&quot;middle_of_the_page&quot;>)

if it's too expensive for you, you still have pepperpepsi's trick (adding the onclick...)

but still, <a href=&quot;javascript:some_function('some text')&quot;> should be working

(and if it sounds simple it's only because i'm really really lazy so i'll never go to complex solutions if there's an easy one on my way ;-))
 
if you're using this function:

function someFunc()
{
svpos=document.body.scrollTop;
shpos=document.body.scrollLeft;
setTimeout(&quot;scroll(shpos,svpos)&quot;,1)
//the rest of your code
}

you can leave the href=&quot;#&quot; and it will reposition itself exactly at the scroll position it was out, however, im not sure why you're having this problem anyways either :eek:) jared@aauser.com
 
Jaredn, Tom,iza,PepperPepsi - I appreciate your efforts very much.
The 2nd idea of Jarden is great and working, even in asp:
function someFunc()
{
svpos=document.body.scrollTop;
shpos=document.body.scrollLeft;
setTimeout(&quot;scroll(shpos,svpos)&quot;,1)
}
function winOpen(x,y)
{if (IE) //Explorer only
someFunc();
//rest of the code...
}
<a href=&quot;#&quot; onclick=&quot;winOpen(a,b)&quot;...>
-----------------------------------------------------------
I also tried to use Jaredn/iza idea:
<a name=&quot;no&quot; onclick=&quot;someFunc()&quot; href=&quot;#no&quot;>tok</a>
It works great in pure html page, but not in asp page (server side bulshit).
even if I save the file after it's been made from asp, as html, it's great. So I learned some stuff here for sure.
But I still need it to work as asp. Maybe the problem is ASP and not jscript at all.
I used the following:
&quot;linkNo&quot; is a variable I increment in a loop for each link,:
Response.Write(&quot;<td><a name='&quot;&linkNo&&quot;' href='#&quot;&linkNo&&quot;' onclick=&quot;&quot;winOpen('&quot; & url &&quot;','&quot; & txt &&quot;')&quot;&quot; onmouseover=&quot;&quot;return setStatus('&quot; &URL& &quot;')&quot;&quot; onmouseout='return setStatus(&quot;&quot;&quot;&quot;)'>&quot;&Left(rs.fields(&quot;Title&quot;),52)&&quot;</a>&quot;)
[PepperPepsi, I use &quot;return true in the function itself).
----------------------------------------------------------
I'll need to find something for netscape too.

I'll try to ask asp experts. If you are too, that's good.
So...thanks a lot in the mean time. I sure learned lots of stuff here.
P.s - I'l check again the javascript:void(0)...
:)
 
Oh............I just tried something else that solves all my problems (until I find new ones):

function winOpen(x,y)
{//rest of the code...
}
Then INSTEAD of the following line:
<a href=&quot;#&quot; onclick=&quot;winOpen(a,b)&quot;...>
I used:
<a href=&quot;javascript:winOpen(a,b)&quot;...>

though I tried lots of things before, it's working now:
The status bar looks great, all links are working in both browsers, whole list does not look again as visited links,
and the page stays as I left it (with no need to place anchors).
I hope that tomorrow it'll stay that way.
I always get back the next morning, and something gets wrong...
Thanksssssssssssss alllllllllllllll
:) -) :)


 
happy to know that 1- you finally done what you wanted to ! and 2- the <a href=&quot;javascript:some_func()&quot;> works ! (it had to be !)
 
3-your ideas were good as well, and will serve me and others too I'm sure, in the future.
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top