By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,401 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,401 IT Pros & Developers. It's quick & easy.

Workaroud for Ctrl-Click in Firefox

P: 1
I saw a post about this issue, but it seemed to be closed.

I needed a code that allowed to handle click + ctrl in a form object such as a textfield. In order to work also on IE, I wrote the textfield onclick property like this

onclick="function(event){ if( event.ctrlKey) this.select()}"

and ... for Firefox, I wrote this piece of code inside a script element:

function clickPlus(){
try
{
window.addEventListener('click' ,
function(e)
{
if(e.target.tagName == 'INPUT')
{
if(e.ctrlKey)
{
try
{
e.target.select();
}
catch(ie){}
}
}
} , true);
}
catch (ie) {}
}

The try-catch around is a way to prevent IE complaining. Now it works in both browsers. The function was called in the body onload event.
Oct 22 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Welcome to TSDN!

Thanks for sharing this code.

I saw a post about this issue, but it seemed to be closed.
This was probably because it was in the newsgroup archives.

The try-catch around is a way to prevent IE complaining.
You could check for support of window.addEventListener instead.

Have you tested in other browsers?
Oct 22 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.