Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable items in right-click context menu?

Status
Not open for further replies.

gana78

Programmer
Apr 12, 2001
30
US
Is it possible to disable selected items in the context menu that appears when you right click (on a link, say?)

Here is my problem:

I am generating huge reports on my web app. and then showing a link to them on the browser. No matter how many times we tell the users, and put in messages, they keep opening those huge (upto 15MB) excel files instead of saving them first on their local. Then they come and complain it takes a lot of time to download it.

I would like to disable the "Open" and "Open in new window" options in the right-click context menu for that link.

If someone knows how this can be done please let me know.

Thanks
Gana
 

there has been alot of discussion on how to disable the right hand click as to protect the code from being viewed...this is impossible of course, since they can go to the view-->source to find out.

but your situation is diff in that you NEED only the right click disabled...by disabling it you are able to eliminate the open/open new window option, unless you still need some of the items in the right click.

which is the exact situation?

- g
 
If you put the Excel spreadsheets in a zip file, then the link won't open 'em, but instead prompt the user to download the file. Voila.

Cheers,
[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Thanks for the replies.. but I am still stuck with this.

Zipping the file:

The excel file is being generated just at that time from the database. I have no idea on how to zip it on the fly.

Using content-type & header information to force-download:

Tried this, but the excel files can be as large as 12-15MB and so the application server bombs.

Disabling entire right-click:

I need the user to be able to "Save Target As..." the file. This is available only in the context menu which comes on when right-clicking.

Custom context-menu (like those in dynamic drive):

I need to be able to trigger a "Save Target As.." Is there a function? Something like linkid.saveTargetAs(); would help a lot.

As of now I have disabled left click and instead alert the user to right click and choose save, but they still click on Open...

Thanks
Gana
 
Gana,

1. There are server-side zip functions, but I don't know how to use them. One of our programmers has done this before, but he's not handy to ask. In about five seconds, I found this site:
so you might do okay by hunting for "server-side zip". If you tell your users this is a "security measure", then they'll feel important doing this, especially if the zip util zips it with a password.

However, you want a fast answer and you want to force them to manipulate the file on their hard drives, so here's what I suggest:

2. Have the server serve the file as something that cannot be run via a browser, such as "Data03272003.local" or just "Data03272003". Instruct your users on that web page to save the file to their hard drives and rename it to "Data03272003.mdb" before running it.

Now, the downside to this is the half-smart users who tell their browsers "open all .local files using Access!" and just cock it back up for you. Eventually, they'll start telling others and, well, it's all in the chipper again until you monkey with the suffix again.

Here's another solution:

3. Don't have a download link at all. Have a download button that retrieves a location on their hard drive and THEN sends the query to the server and has the server throw the file right on their hard drive. Hell, if they can't follow directions, you can't be blamed for treating them like whiny customers in a French restaurant.

I tried to think of a 4th solution, 'cause I like even numbers, but I'd call this a half-solution:

4. I'm pretty sure that you can reroute the action for a link by applying an onclick event, and that means you can pretty much do anything once they click it that you want. In that case, your question might be "How to I code the onclick event to copy a file from the server to the User desktop?" You'll need more than JavaScript to do that.

Cheers,
[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top