1

I am designing a web site with CodeIgniter and I want to open some URL when user click on its buttons (URLs have to open in new tab). I use this code and it works when you want to open URL in same tab, but I want the URL to open in a new tab. I don't want to use JavaScript function too.

<button type="button" onclick="location.href='http://google.com'">Google</button>
Rob Quincey
  • 2,834
  • 2
  • 38
  • 54
  • You should use the tag instead and style it as a button. – AJ X. Nov 14 '16 at 20:10
  • 1
    basically, open an url on a new tab it's a user preference. http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript – McNets Nov 14 '16 at 21:29

2 Answers2

2

If you could change your button to be an anchor...

<a href="http://google.com" target="_blank">Google</a>

Then you could add styling to your anchor... if this is even required.

David Espino
  • 2,177
  • 14
  • 21
0

Try something like this

<button type = "button" onclick = "location.href = window.open('link')"></button>
Abhishek Pandey
  • 13,302
  • 8
  • 38
  • 68
WholesomeGhost
  • 1,101
  • 2
  • 17
  • 31