views:

2342

answers:

1

Background

I'm using POST form submissions instead of links with concatenated arguments inside a Web application, so I can exercise control over input.

Unfortunately this means users can't use the quick shortcuts they know to open links in new windows, like control-clicking or middle-clicking.

Problem

I've got what seems to be a workable way to use jQuery to capture mouse input and the various chord keys, based on the W3C DOM mouse events specification:

 $("span#clickspan").click( function(event) {

   buttonpress = event.button;
   ctrlpress = event.ctrlKey;

    $("#clickresult").empty();
    $("#clickresult").append("<p>Click!</p>");
    $("#clickresult").append("<p>Button # " + buttonpress + " pressed!</p>");
    if (ctrlpress) {
        $("#clickresult").append("<p>Control-click!</p>");
    }

    //form submission code would go here

    event.preventDefault();

    }
 );

I can capture control-clicks this way (tested in Firefox 3 and IE7), and it correctly (?) reports left-clicks as coming from mouse button #0, but for some reason this code still isn't capturing middle-clicks on the span, and right-clicks still pop up the context menu. I'd like to capture middle-clicks, at least.

Can somebody help there?

What "control" means

The problem with a GET submission/link with concatenated arguments is that anybody can edit the address bar and type in anything. I've already worried about authentication and validation server-side. That's not why I want to work with POST.

I should only be showing users information that's meaningful. Internal database IDs aren't. I should only be letting users interact with the application in meaningful ways. Arbitrarily editing the address bar isn't one of those.

People make typos all the time. From the system's perspective, though, there's no difference between a typo in the address bar and a flaw in the application logic, and I'd rather not push the responsibility for deciding which one just happened off onto the users.

+6  A: 

Short answer? Can't do it.

Long answer? Javascript mouse events. Still can't do it.

This begs the question: do you need to use POST or do you simply want to? The only reason why you'd need to is query string length. As to wanting to, you mention "controlling user input". What does that mean exactly?

You should never ever ever rely on the browser for input validation. You can do it there as a convenience but the server should always validate input.

Or is the reason aesthetic (ie shorter, "nicer" URLs)?

You're reinventing the wheel that is hyperlinks. I'm just trying to make sure you have a pretty darn good reason for doing so because it's counterproductive and you're never going to get the same browser support and compatibility as actual hyperlinks. Plus you're likely to simply annoy your users by having things they expect to work not work. Not good.

cletus