467,133 Members | 1,114 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,133 developers. It's quick & easy.

rightclick "openlink" bypasses important javascript

Recently I noticed that if you "right click" and "open link" on my
site, you bypass the javascript code that fires "onclick". I have
several pages that fall victim to this, and I could probably refractor
the page and put checking on both javascript and cs side but before I
did that I wanted to know if there were any other ideas on how to get
around this problem.

I started out by trying to disable the right click, but I don't want
to have an "alert" pop up, I tried fired the "onclick" command on
right click events but this just had an error message pop up, then
still allowed me to still select "open link" from the context menu.

Thanks for you help

Jun 26 '07 #1
  • viewed: 1298
Share:
1 Reply
* je******@smartvoicecast.com wrote, On 26-6-2007 23:16:
Recently I noticed that if you "right click" and "open link" on my
site, you bypass the javascript code that fires "onclick". I have
several pages that fall victim to this, and I could probably refractor
the page and put checking on both javascript and cs side but before I
did that I wanted to know if there were any other ideas on how to get
around this problem.

I started out by trying to disable the right click, but I don't want
to have an "alert" pop up, I tried fired the "onclick" command on
right click events but this just had an error message pop up, then
still allowed me to still select "open link" from the context menu.

Thanks for you help
You cannot really force the script to fire. Remember that there might be
browsers with Javascript disabled, or people just copy/pasting the link
and opening it. If you want to be certain use a LinkButton instead of a
Hyperlink and in the LinkButton.Click server side event do a
Response.Redirect to the new url.

Alternatively you can make the link itself a javascript url like this:

<a href="javascript:if(DoSomevalidation()){window.loc ation.replace('new
url here');}">click me</a>

But this will break the site altogether if you've got scriptless
browsers visiting your website.

Jesse
Jun 29 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Rob McLennan - ZETLAND | last post: by
8 posts views Thread by Rob McLennan - ZETLAND | last post: by
reply views Thread by Peter van der Veen | last post: by
5 posts views Thread by rishabhshrivastava@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.