MAX POWER
MAX POWER

Reputation: 5448

append a GET variable to a link when clicked

Suppose I have URL such as:

<a href="images.php?id=15645" rel="gallery">

There is already a click handler on this URL (FancyBox lightbox gallery):

$('a[rel=gallery]').fancybox();

I would like to append another GET variable to this URL (title="mytitle"), but ONLY when it is clicked. The GET variable must not be displayed to the user in the status bar (at the point the link is clicked or afterwards when hovering over that same link). Basically the GET variable doesn't actually get added to the link, it just gets "sent" with the request.

Upvotes: 0

Views: 650

Answers (2)

andres descalzo
andres descalzo

Reputation: 14967

try this:

html

<a href="images.php?id=15645" rel="gallery">example</a>

JS:

var 
    agallery = $('a[rel=gallery]'),
    orig = "";

var onstart = function() {
    agallery.attr('href', function(i, a) { orig = a; return (a +'&title="mytitle"'); });

};

var onend = function() {
    agallery.attr('href', orig);
};

$('a[rel=gallery]').fancybox({
    onStart: onstart,
    onComplete: onend,
    onCancel: onend
});

Upvotes: 1

Ian Wetherbee
Ian Wetherbee

Reputation: 6109

Can't be done, GET variables are passed via a URL. You'd need to pass them via POST to hide them from the URL bar, but even then anyone can see what is being submitted.

Upvotes: 0

Related Questions