/    Sign up×
Community /Pin to ProfileBookmark

Is there a way

to make an onMouseOver alert() only alert once? Like:

<a href=”somewhere.com” onMouseOver=”alert(‘haha’)”>somewhere.com</a>

And it only alerts once?

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@slynxJan 26.2003 — Have the onMouseOver call a function that has the alert in an if statement that checks a flag variable (set to 0 outside the function. Set the flag to one in a statement after the alert.
Copy linkTweet thisAlerts:
@CharlesJan 26.2003 — [font=monospace]<a href="http://www.w3.org/" onmouseover="alert(); this.onmouseover = function () {}">W3C</a>[/font]
Copy linkTweet thisAlerts:
@azcn2503Jan 26.2003 — Don't know if this will work....

<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script language="javascript"&gt;
alerted=0;
function alerter(text){
if (alerted==0){
window.alert(text);
}
if (alerted==1){
// no action performed
}
alerted=1;
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;a href="#" onMouseOver="alerter('HAHAHA!');"&gt;Ha!&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@khalidali63Jan 26.2003 — [i]Originally posted by azcn2503 [/i]

[B]Don't know if this will work....

[/B]
[/QUOTE]


......Just curious,why post it if you don't know its going to work or not??????

cheers

Khalid
Copy linkTweet thisAlerts:
@azcn2503Jan 26.2003 — It does work though ?

I thought I may as well have a go.
Copy linkTweet thisAlerts:
@JonaauthorJan 26.2003 — Thanks guys, I was just curious.. ?
Copy linkTweet thisAlerts:
@JonaauthorJan 26.2003 — Charles, why do you always use the, "var = function() { }"?

I mean, it's shorter than the way I code, but mine (to me anyway) has more logic. Just wondering ? I think I'm always too curious lol.
Copy linkTweet thisAlerts:
@CharlesJan 27.2003 — [font=georgia]To me that use of anonymous functions is much more logical. And it is consistent with the object oriented nature of JavaScript. See my post towards the end of http://forums.webdeveloper.com/showthread.php?s=&threadid=2852. Also, you need to keep in mind that each line of code in JavaScript carries a great deal of overhead. I always try to keep things as short as possible and I never use a variable if I can avoid it.

But let's consider your example. With the other method proposed, each time the link's onmouseover handler is called, the interpreter has to look up the variable name, get its value, compare it and decide what to do. And at each of those steps a good deal is going on unseen. With my method, the first time the handler is called the alert is called and then the handler overwrites itself. With each subsequent call the handler simply does nothing. Call me nuts, but that seems to make more sense to me.[/font]
Copy linkTweet thisAlerts:
@JonaauthorJan 27.2003 — On the contrary, it makes very good since, Charles. Very good sense. As a matter of fact, I like the way you "code." The shorter the better--especially for the people with the old Windows 3.1 with a 16K modem! Hehe, I don't even think they'll be able to view it! That version of JavaScript wasn't released when I first got online with my 3.1.. Anyways, back to our discussion--your code is very well put together. It is, at first glance, a bit odd, but when explained, makes very good sense. There seems to be more logic in azcn2053's code to me, but I understand variables, loops, etc., which is what he used. In your code, I am unfamiliar with it. Both work, at least on a Windows Me with 360+ MB memory.. Well, I hope to speak with you again, Charles. Your method of coding is very interesting, and I look forward to seeing your other ways of getting around the "long" functions... personally, I always make very short code. Many DHTML scripts are rather lengthy, but I always try to shorten them up a little, because I know what it's like to have a 28.8 and 56K modem.
Copy linkTweet thisAlerts:
@CharlesJan 28.2003 — [font=georgia]If you are wed to the setting a flag method and you still want to keep your code as elegent as possible then try:[/font]

[font=monospace]

<a href="http://www.w3.org/" onmouseover="if (!window.doneThat) {alert(); window.doneThat = true}">W3C</a>[/font]
Copy linkTweet thisAlerts:
@JonaauthorJan 28.2003 — Now that makes sense off the top of my head. ?

These little "tid-bits" will really help me later on in life ?
×

Success!

Help @Jona spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...