gyra
asked on
CrossBrowser Ctrl+Click, regular Click call function detection...
Hey all, here's what i'm trying to do. I have a link, i want it so that when you click this link it calls a function, and if you control click on the link, i want a different function to be called. Can this be done? How? Thanx all.
ASKER
okay, that seemed to work, but the only problem is this, in firefox and ie7, when i ctrlClick on the link, it opens up a new window for the link. How do i stop the window from opening up?
Ok, replace
<a href="#" onClick="testCtrl(event)" > Click this link </a>
with this:
<a href="javascript:void(0)" onClick="testCtrl(event)" > Click this link </a>
or with this:
<a href="#" onClick="testCtrl(event);r eturn false;" > Click this link </a>
<a href="#" onClick="testCtrl(event)" > Click this link </a>
with this:
<a href="javascript:void(0)" onClick="testCtrl(event)" > Click this link </a>
or with this:
<a href="#" onClick="testCtrl(event);r
ASKER
I tried both and it either solution works fine for IE, but for firefox it still opens a new window/tab.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow, NICE!
Real cool, fake it out! Worked great! Thanx man a million
gyra
Real cool, fake it out! Worked great! Thanx man a million
gyra
<html>
<head>
<script>
function ctrlYes() {
alert('Ctrl!');
}
function ctrlNo() {
alert('No Ctrl!');
}
function testCtrl(event) {
if (!event) event = window.event;
if (event.ctrlKey == true) {
ctrlYes();
}
else {
ctrlNo();
}
}
</script>
</head>
<body>
<a href="#" onClick="testCtrl(event)" > Click this link </a>
</body>
</html>