Can I use onclick to stop access to a link?

I have used the form of onclick that allows you to request the user to confirm or cancel an action - for example:

onclick=“return confirm(‘Are you sure you want to delete user?’)”

But now I want to block the action - for example, I have a button to take the user to another screen to purchase a product, but if the user isn’t logged in, I want to pop up a window that says ‘Sorry, you have to log in first’ and only allow the user to respond ‘OK’ which will leave the screen as it is - not go to the link.

Is this possible?

onclick="alert('Sorry, you have to log in first!'); return false;"

Don’t forget to perform a logged-in check on the destination page, for when scripting isn’t being used, or for when someone has bookmarked that page, or if someone tries to get around your security, or … you get my drift.

Great! That worked… And thanks for the good advice about checking in the destination page too.

Where can one get information like this - I searched all over the internet and didn’t find any descriptions of this function or how the srcipts work.

Sometimes it’s just a matter of knowing what to ask.

Paul, I think we have a new verb: “Let’s lmgtfy him.” :slight_smile: Though I’m at a loss on knowing how to pronounce it…

Off Topic:

I like to pronounce it as legit-if-eye

Now, the problem with googling is that if you use the wrong names for something, you get nowhere fast. How many people look for a “footer that always stays at the bottom of the page” when they’d get way more hits googling for “sticky footer”?

I agree with you, it helps to know the magical incantations to use - in this particular case, Catfish Footer :magic:

[ot]Hahaha, you know how long I was here before I realised (by accidentally using a JS-enabled browser) that such a thing existed??

Then again, the clicking on someone’s name and getting a little menu box instead of their user page also freaks me out.[/ot]

Off Topic:

We may have to take this discussion elsewhere. I agree though about the menu box. There’s no discoverability at all. The link needs to indicate in some way that it behaves differently. An icon beside of for a context list perhaps.