Here is my sample http://jsfiddle.net/RaQtg/4/ I want to redirect my page to another URL by pressing G key, But I couden't trigger click function.
any ideas?
thanks
Here is my sample http://jsfiddle.net/RaQtg/4/ I want to redirect my page to another URL by pressing G key, But I couden't trigger click function.
any ideas?
thanks
.trigger() like .click() can only work if you defined an event handler using .bind()(or .live()or .on() and all shortcuts available) methods.
try instead
$(document).on('keydown', function(e) {
if (e.keyCode === 103) //G key is pressed
{
alert("g key is pressed");
location.href = $('mylink').attr('href');
}
});
This seems to work for the key g
$(document).on('keydown', function(evt) {
if (evt.keyCode == 71) //G key is pressed
{
window.location = "http://"+$('.mylink').attr("href");
}
});
Example here http://jsfiddle.net/yDsC8/
.trigger() triggers a specific event bound to the link. If you do not have a function bound to an item's keyup event, you cannot trigger said keyup event..