views:

269

answers:

3

Is it possible to suppress the default IE 7 functionality when CTRL+click on link opens a new window? if so, how?

Thanks!

+1  A: 

The jQuery event.preventDefault() method or similar can override default behavior on pages that you have control over.

It is generally bad practice to alter the behaviour of a user's browser without really good reason as the browser and its behaviour is "their's".

msw
i am planning to do in for nodes in a tree. they are supp. to be clickable but not open links. I am not going to do this for traditional links.
gnomixa
A: 

Add script to the anchor and return false

<a href='some.htm' onclick='return false;'></a>

And it is valid to use anchors in a treeview because it makes the treeview more accessible.

James Westgate
+1  A: 

There is no way to suppress a Ctrl+Click on a link in Internet Explorer -- the onclick event doesn't fire at all for link clicks if the Ctrl key is held down. It seems that Microsoft don't want you to change this functionality out of fear that you might confuse the user :-)

I searched for some sort of official confirmation/explanation before posting this answer, but unfortunately this limitation is not listed in the documentation on MSDN and Google wasn't helpful. Never-the-less, it remains true, try it yourself:

<a href="http://stackoverflow.com" onclick="alert('Hello');">Hello</a>

You will find that a Ctrl + click on the link will not throw the alert box.

Andy E
yeah i figured already....i will go with the out of the box behaviour for the tree control and call it a day
gnomixa