Search code examples
internet-explorer-7clickctrl

IE 7 CTRL + click opens a new window - how to suppress it?


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

Thanks!


Solution

  • There is no way to suppress a Ctrl + Click on a link with no child elements 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. Nevertheless, it remains true, try it yourself:

    <a href="#" onclick="alert('Hello');">Hello</a>
    

    You will find that a Ctrl + click on the link will not throw the alert box. According to pinkgothic, assigning a child element to the link will work around the problem. For example:

    <a href="#" onclick="alert('Hello');"><span>Hello</span></a>
    

    This works because the click is triggered for the <span> element first, before propagating to the <a> element.