Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Page refresh on click compulsory?

10 views
Skip to first unread message

bit-n...@hotmail.com

unread,
Jul 22, 2016, 9:51:59 AM7/22/16
to
If I click on something, does it ALWAYS mean that the page will blank, and the next page will be got? How is this prevented exactly? If I just do a "addEventListener" with a "click" argument, will it be prevented? (say I just want some type of "box" to popup when a particular link is clicked, as I've seen on many sites....)
I'm still new to this stuff, so learning.... :)


Thanks.

Evertjan.

unread,
Jul 22, 2016, 10:42:56 AM7/22/16
to
bit-n...@hotmail.com wrote on 22 Jul 2016 in comp.lang.javascript:

> If I click on something, does it ALWAYS mean that the page will blank,
> and the next page will be got?

No.

> How is this prevented exactly? If I just

It is not true. It does it ALWAYS mean that.

> do a "addEventListener" with a "click" argument, will it be prevented?

Why not start with easier to understand:

onclick = '....';

[see below]

> (say I just want some type of "box" to popup when a particular link is
> clicked, as I've seen on many sites....)

I don't understand your "just",
because it does it ALWAYS mean that.

> I'm still new to this stuff, so learning.... :)

Do you think that learning is 'just' for beginners?

============================

Answer, [although it is all over the web]:

Have your code return *false*:

<myElement onclick = 'myFunction1();myF2();return false;'> ...

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Ben Bacarisse

unread,
Jul 22, 2016, 11:29:03 AM7/22/16
to
bit-n...@hotmail.com writes:

> If I click on something, does it ALWAYS mean that the page will blank,
> and the next page will be got? How is this prevented exactly? If I
> just do a "addEventListener" with a "click" argument, will it be
> prevented?

If you install the event handler using addEventListener, you have to
cancel the event's default behaviour by calling

event.preventDefault()

in the handler function. There's also the possibility that you don't
want the event to propagate further up (or down) which you would do with
event.stopPropagation().

<snip>
--
Ben.
0 new messages