keithamus / jwerty

⌨ Awesome handling of keyboard events
http://keithamus.github.io/jwerty
Other
1.21k stars 109 forks source link

Keyboard shortcut to launch modal window... #41

Closed webmastervinay closed 11 years ago

webmastervinay commented 11 years ago

0 down vote favorite

I am uing your link for integrating keyboard short cuts.. It redirects to the given URL after pressing the key..

jwerty.key('f2', function () { window.location = document.getElementById('SaleLink').href; });

I am using following code to launch the bootstrap modal window :

[a href=PopUp.php?Id=1 data-toggle="modal" data-target="#myModal">Open</a]

$('#myModal').modal({ show: false});
$('#myModal').on('hidden', function () {
    console.log('modal is closed');
})
$("a[data-toggle=modal]").click(function (e) {
lv_target = $(this).attr('data-target');
lv_url = $(this).attr('href');
$(lv_target).load(lv_url);
}); 

It works fine when i click on the link...i am trying to add this code to launch the modal window when i press a key say f2 ...since it redirects directly to the given URL therefore the modal window is not opening....Can you please suggest any solution for this??

keithamus commented 11 years ago

You need to simulate the click of the link instead of changing window.location, so your code should be

jwerty.key('f2', function () {
    $('#SaleLink').click();
});
webmastervinay commented 11 years ago

thanks a lot keithamus!!!