Search code examples
javascripthtmlbuttonwindownew-operator

Open button in new window?


How would I go about making the button open in a new window, emulating "a href, target = _blank"?

I currently have:

<button class="button" onClick="window.location.href='http://www.example.com';"> 
     <span class="icon">Open</span>
</button>

The button isn't in a form, I just want to make it open in a new window.


Solution

  • Opens a new window with the url you supplied :)

    <button class="button" onClick="window.open('http://www.example.com');">
         <span class="icon">Open</span>
    </button>