Javascript: How do I?
How do I attach a "listener" to a hyperlink such that clicking the hyperlink will fire off a function before the browser actually requests the document in the href?
If I put something in onClick, doesn't that override the click and prevent the browser from requesting the linked URL? Or will it do both?
muppet
September 9th, 2006 7:03pm
<script>
function myFunction(){
//do stuff
document.window.location = "
www.blah.com";
}
</script>
<a href="javascript:myFunctions()">My Link</a>
Funny Bünny
September 9th, 2006 7:09pm
Why not add document.location.href = "whereveryouwanttogo" to the end of the call to the listener? Doesn't answer your question exactly, but it avoids the need to even ask it. :)
Thanks. I think I see how to modify that for my framed situation.
And I assume that if a user is blocking ALL javascript, the link will just work off the href attribute.
muppet
September 9th, 2006 7:11pm
Alternatively, this would take you... like, five seconds to try.
Colm
September 9th, 2006 7:11pm
if I do href="mylocation" onClick="myfunction" anyway.
muppet
September 9th, 2006 7:11pm
Easier to ask since you're all so knowlegable. I'm going for efficiency here, Colm.
muppet
September 9th, 2006 7:12pm
Right, why bother wasting 5 seconds of your own time when you can waste ours instead?
Colm
September 9th, 2006 7:13pm
Yeah, like any of us was doing anything productive. :)
Colm just likes so find fault with me because he's secretly so jealous of me that it makes him cry at night.
muppet
September 9th, 2006 7:19pm
Uuuuh... jealous of what?
Funny Bünny
September 9th, 2006 7:23pm
Dude, what's NOT to be jealous of when it comes to me? I'm so fucking awesome it makes ME cry.
muppet
September 9th, 2006 7:24pm
Right. Carry on muppy.
Funny Bünny
September 9th, 2006 7:25pm
>Dude, what's NOT to be jealous of when it comes to me?
Every other post on here is a complaint about your life. Either your job sucks, you're ill because of your drugs or you're poor.
Colm
September 9th, 2006 7:31pm
lol
Thats a pretty acurate list.
Funny Bünny
September 9th, 2006 7:35pm
" Either your job sucks, you're ill because of your drugs or you're poor."
heh. and every second post you make is attacking muppet.
so...which of you has the sadder life?
worldsSmallestViolin
September 9th, 2006 7:57pm
Yeah, and like muppet is any different.
Rick Zeng/Tseng
September 9th, 2006 8:01pm
true. every second post muppet makes is _also_ about muppet.
<g> but I put it to you that muppet has rather more of an investment in muppets life than Colm has.
...at least, I would have thought so...
worldsSmallestViolin
September 9th, 2006 8:03pm
Lets stop derailing the thread, muppet is boring
what are you snorting for?
September 9th, 2006 8:06pm
His posts are boring.
Muppet himself is a fun subject :)
Just like a bot is a fun subject...
Rick Zeng/Tseng
September 9th, 2006 8:08pm
>but I put it to you that muppet has rather more of an
>investment in muppets life than Colm has.
Gee, I hate to agree with you here, but I really DON'T care about muppet's life. I care even less about how much you care about me not giving a shit about muppet, however, and I'm frankly baffled as to why you give a shit about me.
Put simply... why are you still talking?
Colm
September 9th, 2006 8:08pm
He's probably still talking for the same reason you just made that post, Colm.
Because I can.
Rick Zeng/Tseng
September 9th, 2006 8:10pm
The proper way to do it would be (with prototype)
<a id="hi" href='
http://crazyontap.com' > Link 1 </A>
<script >
Event.observe( $('hi'), "click", function1, true);
function1 = function(e){
Event.stop(e); // Stops the click event
//Do Stuff
//If you want still to trigger the click funcion
Event.element(e).click();
}
</script>
But yeah, the others also work :)
>He's probably still talking for the same reason you just
>made that post, Colm.
Which was?
Colm
September 9th, 2006 8:13pm
"I really DON'T care about muppet's life."
interesting. you claim that, but yet I still read a _lot_ of posts by you about muppet, his life and his posting techniques.
seems like a lot of work for someone who doesn't care about the topic.
"Put simply... why are you still talking?"
becaues I get a real kick out of baiting people less intelligent than myself.
worldsSmallestViolin
September 9th, 2006 8:15pm
You can really tell who are young and who aren't.
Rick Zeng/Tseng
September 9th, 2006 8:16pm
>interesting.
Ah, see that's where you went wrong. You're actually being very, very dull.
Colm
September 9th, 2006 8:18pm
Interesting enough to get Ms WsV
Rick Zeng/Tseng
September 9th, 2006 8:20pm
"who are young and who aren't"
You really aren't ever going to get the hang of this English language thing, are you Rick? :-)
You have been living in Canada for a good many years now, and you must therefore have to speak English every day. Why do you have so much trouble learning it?
bon vivant
September 9th, 2006 8:30pm
Cause no one is correcting your mistakes.
And I don't really want to learn!
Rick Zeng/Tseng
September 9th, 2006 8:32pm
> And I don't really want to learn!
As the saying goes, once in Rome... If you don't want to learn it, why did you move there?
Funny Bünny
September 9th, 2006 8:39pm
I mean I don't want to perfect it.
There are more important stuff to learn and do.
Rick Zeng/Tseng
September 9th, 2006 8:41pm
Such as what?
Colm
September 9th, 2006 8:42pm
Oh, perhaps I am just lazy.
It's too hard to move back.
Rick Zeng/Tseng
September 9th, 2006 8:42pm
> It's too hard to move back.
How good is your cantonese, btw?
Funny Bunny
September 9th, 2006 9:16pm
Very good.
On the other hand, writing proper Chinese is ever harder, and I have not do it for far too long to catch up.
Rick Zeng/Tseng
September 9th, 2006 9:28pm
Have not done...
Rick Zeng/Tseng
September 9th, 2006 9:30pm
Basically, you're an international analphabet. If the canadian government wanted to deport you, they'd be fucked.
Funny Bünny
September 10th, 2006 6:18am