rightclick "openlink" bypasses important javascript

  • Thread starter Thread starter jerunyon
  • Start date Start date
J

jerunyon

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
 
* (e-mail address removed) 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.location.replace('new
url here');}">click me</a>

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

Jesse
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top