Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,005 members, 7,806,921 topics. Date: Wednesday, 24 April 2024 at 07:00 AM

Quick Javascript Pop Quiz - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Quick Javascript Pop Quiz (1059 Views)

How To Add A Pop-up On Your Wordpress Website / Most Confusing And Simple Maths Quiz / Dhtml Quiz: How Will You Detect If A Browser Support Javascript From Php Code? (2) (3) (4)

(1) (Reply) (Go Down)

Quick Javascript Pop Quiz by yawatide(f): 11:14am On Nov 23, 2009
So, I see this a lot on various websites and it is quite annoying. Some Nigerian websites are no exception. Here is the scenario:

A developer wants to have a popup on a page, upon onclick. Popup comes up fine but in FF (not too sure about IE since I rarely use it grin), each time you click, even if the link/image/whatever is at the bottom of the page, the page always scrolls to the top. If you have encountered such and are like me, this can be quite annoying. The page should remain where it is and not scroll to the top.

The code more often than not looks like so:

<a href="#" onclick="somePopUpFunction()">click here</a> (Feel free to copy this code and paste at the bottom of any of your sites then click the link to verify the issue as stated).

Technically, there is nothing wrong with the code above, except of course of the issue of scrolling to the top.

Question?
How would you modify the code above to prevent the page from always scrolling to the top?

As always, I will wait for a few answers before answering, assuming no one has it right by then.

Good luck!
Re: Quick Javascript Pop Quiz by Nobody: 8:25pm On Nov 23, 2009
<a href="#" onclick="somePopUpFunction();return false;">click here</a>

or

<a href="javascript:void(0)" onclick="somePopUpFunction()">click here</a>
Re: Quick Javascript Pop Quiz by yawatide(f): 8:55pm On Nov 23, 2009
that was too quick. why did you have to spoil the fun? I was thinking I would have to change the subject header to "site review" before I get a response cool

Anyways, though both your solutions do the trick, #1 is preferred - some say that void(0) is invalid javascript and that if you check your console (FF. I haven't done this but take their word for it), void(s) generates an error as it returns "undefined" and it is possible that what you are clicking isn't undefined.

Let me see if I can come up with something else cool
Re: Quick Javascript Pop Quiz by Nobody: 2:58pm On Nov 24, 2009
sorry, i should not have spoilt the fun . . nice quiz sha
Re: Quick Javascript Pop Quiz by kolitos007: 3:15pm On Nov 24, 2009
lol, that was excellent dhtml lol didn't even give us chance hehe
Re: Quick Javascript Pop Quiz by Nobody: 5:09pm On Nov 24, 2009
i think yawa should have filtered me out. . .the answer is similar to one quiz yawa posted some time back. . something concerning links
Re: Quick Javascript Pop Quiz by yawatide(f): 5:56pm On Nov 24, 2009
dhtml, so you cheated? tongue
Re: Quick Javascript Pop Quiz by Nobody: 10:39pm On Nov 24, 2009
^Now how did i cheat?
Re: Quick Javascript Pop Quiz by yawatide(f): 11:37am On Nov 25, 2009
the answer is similar to one quiz yawa posted some time back.

The above implies inside trading and in some countries, you, like bernie maddoff, would go to jail for a long time tongue
Re: Quick Javascript Pop Quiz by quadrillio(m): 1:21pm On Nov 25, 2009
DHTML, is not a cheat, he's just smart.

yawa-ti-de:

The above implies inside trading and in some countries, you, like bernie maddoff, would go to jail for a long time tongue
grin grin grin grin grin
Re: Quick Javascript Pop Quiz by gozzilla(m): 6:04pm On Nov 29, 2009
See men yawning
Re: Quick Javascript Pop Quiz by Nobody: 6:06pm On Nov 29, 2009
. . .strolling. . .
Re: Quick Javascript Pop Quiz by remoranger(m): 9:18pm On Nov 29, 2009
strolling, scratching ma balls and chewing corn.
Re: Quick Javascript Pop Quiz by yawatide(f): 9:40pm On Nov 29, 2009
remo:
cold don catch you finish? You don score yet? tongue
Re: Quick Javascript Pop Quiz by remoranger(m): 11:28pm On Nov 29, 2009
@yawa

it depends on your definition, lol.

(1) (Reply)

Help Out Pls / How Do I Add A customize Jpeg Colour Background in DW? / Best Practices For E-commerce Web Design

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 13
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.