₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,018 members, 8,419,963 topics. Date: Thursday, 04 June 2026 at 08:24 AM

Toggle theme

Quick Javascript Pop Quiz - Webmasters - Nairaland

Nairaland ForumScience/TechnologyWebmastersQuick Javascript Pop Quiz (1161 Views)

1 Reply (Go Down)

Quick Javascript Pop Quiz by yawatide(op): 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(op): 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(op): 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(op): 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(op): 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

How To Add A Pop-up On Your Wordpress WebsiteMost Confusing And Simple Maths QuizDhtml Quiz: How Will You Detect If A Browser Support Javascript From Php Code?234

Google Adsense Also Known As Crapsense Is Digital Slavery!How To Earn Money Via Your Website Or Blog?Download 30 Wordpress Premium Plugins + 14 Wordpress MP4 Video Training Series