0

Newbie question here. The following link works well to open a new window to a specified webpage.

<a onclick="window.open('','page','location=0,toolbar=0,...')"
href="mypage.html" target="page">My Link</a>

I need to replace the link with a button, but can't get it to work. Here's what I've got:

<button onclick="window.open('','page','location=0,toolbar=0,...')" 
href="mypage.html" target="page"
type="button">My Button</button>

It appears that href and target are not attributes of button. Looking for recommendations how to fix this for best browser compatibility.

TylerH
  • 20,799
  • 66
  • 75
  • 101
ggkmath
  • 4,188
  • 23
  • 72
  • 129
  • 1
    Just put the URL to be opened as first parameter into the `window.open` call in the first place …? But this is kinda nonsense – functionality that refers to other pages _should_ be using links. If you want a link to _look_ like a button, then format it with CSS. – CBroe Apr 01 '14 at 14:03
  • Why do you want to use ` – Nick Apr 01 '14 at 14:07
  • The HTML "theme" I'm using states `it is a best practice and highly recommended to use the – ggkmath Apr 01 '14 at 14:15

2 Answers2

3

why not try:

<a onclick="window.open('','page','location=0,toolbar=0,...')"
href="mypage.html" target="page"><button>My Link</button></a>
Ritikesh
  • 1,228
  • 1
  • 9
  • 19
  • Any pros or cons versus just including the webpage link as the first parameter in the `window.open()`? – ggkmath Apr 01 '14 at 14:13
  • 2
    Possible duplicate of: http://stackoverflow.com/questions/233467/whats-the-best-way-to-open-new-browser-window And I don't really see any pros or cons of specifying links in the first parameter. if you use a button, you can add the url as the first parameter of the window.open() function and ignore the target and href attributes unsupported by button! – Ritikesh Apr 01 '14 at 14:20
0

This should work

<button onclick="window.open(yourwebsite+'/mypage.html')">My Button</button>
Anubhav
  • 7,138
  • 5
  • 21
  • 33