Search code examples
phpcssinternet-explorercontextmenuright-click

Right-click tabs doesn't work on Internet Explorer


We have some CSS buttons. In Chrome and other browsers, when you right-click on the button you get the expected options: open in a new tab, open in a new window, etc.

However, in Internet Explorer, when you right-click, it's not that normal right-click/open in new tab menu. Instead it says, (Undo, cut, copy, paste, delete, select all, inspect element).

The HTML looks like this:

<a href="http://www.example.com/button_link.php"><button class="my-button">Click Here</button></a>

And the CSS looks like this:

.my-button {
  border: 1px #000000 solid;
  line-height: 1.1em;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  border-radius: 5px;
  background: #eef0f1 repeat-x url("data:image/png;base64,___base_64_stuff_here_____");
}

Any thoughts as to why I have the option to "open in a new tab" with Chrome, Opera, others but not with Internet Explorer?


Solution

  • Putting a button inside an anchor tag doesn't make sense.

    There are several ways you can do this. One of them is to use JavaScript. You can use plain JavaScript to achieve this:

    <button class="my-button" onclick="window.location.href='http://www.example.com/button_link.php';">Click Here</button>
    

    Another method would be to make the link look like a button using CSS and get rid of the button tag completely.