user7405100
user7405100

Reputation:

Open a popup by clicking on a button

I have a link that opens a small popup (not a new tab) to a page. I would like to integrate this function into a button. Unfortunately this doesn't work as hoped.

Good example link:

<a href='#' onclick='window.open **
("https://google.com","mywindow", 
"menubar=1,resizable=1,width=500,height=500")'>
Link</a>

Current button that should do the same:

<form>
  <input class="btnstylega" onclick="window.location.href='https://google.com'" type="button" value="Link" />
</form>

Upvotes: 0

Views: 4030

Answers (3)

Maneesh
Maneesh

Reputation: 408

This is happening because you are setting the window location in one and not creating a new window.

This amended code should work as intended:

<form><input class="btnstylega" 
onclick="window.open('https://google.com','mywindow', 
'menubar=1,resizable=1,width=500,height=500')" 
type="button" value="Link" /></form>

Upvotes: 0

user10993431
user10993431

Reputation:

Use _blank with the target attribute; this will open a new tab:

<form>
  <input class="btnstylega" type="button" value="Neue Versicherung hinzufügen" target="_blank" />
</form>

Or if you want to open a new window, use the onClick attribute:

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

Here, do NOT forget the quotation marks around the "window.open('http://www.example.com');".

Upvotes: 0

Yosef Tukachinsky
Yosef Tukachinsky

Reputation: 5895

why you not try:

  <form><input class="btnstylega" onclick="window.open('https://google.com','mywindow', 
  'menubar=1,resizable=1,width=500,height=500')" 
  type="button" value="Neue Versicherung hinzufügen" /></form>

Upvotes: 3

Related Questions