Monday, November 18, 2013

Javascript: onclick in new tab

The usual onclick event that I use is something like this:

 <div onclick="window.location.href='http://google.com';">Click me!</div>  

If you need it to open in a new tab, you have to modify it a little:

 <div onclick="window.open('http://google.com', '_blank');">Click me!</div>