Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  8] [ 5]  / answers: 1 / hits: 23717  / 11 Years ago, thu, june 13, 2013, 12:00:00

Ok, so i know i can simulate a click by running this code



document.getElementById('recover').click();


the closest this i could find was cntextmenu so i tried



document.getElementById('recover').contextmenu();


however this does nothing



Is it possible to right click and element to bring up the contextual menu so i can click an item on that list ? and if so could someone point me in the correct direction to accomplish such a goal ?



I've done some searching but the only thing i have found is jquery javascript capturing of the event not actually triggering the event


More From » right-click

 Answers
30

with jQuery



$('#recover').trigger({
type: 'mousedown',
which: 3
});


otherwise



var element = document.getElementById('recover');
var e = element.ownerDocument.createEvent('MouseEvents');

e.initMouseEvent('contextmenu', true, true,
element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false,
false, false, false,2, null);


return !element.dispatchEvent(e);

[#77636] Wednesday, June 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dequant

Total Points: 88
Total Questions: 99
Total Answers: 95

Location: Ukraine
Member since Sun, Dec 13, 2020
4 Years ago
dequant questions
;