views:

211

answers:

5

How do you make an HTML button behave just like a hyperlink where, if you click on it, it will open a browser window showing a page you want?

I understand this much. I think I will use this but instead of a link to some javascript code inside the quotes for "onclick" I want to put something simple that will launch a new browser window.

+2  A: 

You could do something like this:

window.open(url, "window-name", "menubar=no,innerWidth=600,innerHeight=600,toolbar=no,location=no,screenX=400,screenY=40");

Passing a name to the open method causes the browser to open a new window. The third argument defines the looks of the new window.

Kees de Kooter
A: 
<input type="button" value="Google"
       onclick="window.open('http://www.google.com', '_blank');" />
Josh Stodola
+2  A: 
In Head:  
<script>
openNewWindow = function()
{
 window.open(url, "_blank");
};
</script>
In Body:    
<input type="button" onclick="openNewWindow()" >

I prefer to define a function named openNewWindow() instead of putting the code in the input tag. This is for organization. I highly recommend you do this if you're planning on having many different buttons for opening different windows.

ItzWarty
+1  A: 

onclick and window.open

<input type="button" onclick="window.open('http://www.example.com','_blank','resizable=yes')" />
S.Mark
+1  A: 

I think this is the best solution for you.

Try this out

<a href="http://www.stackoverlfow.com" target="_"><input type="button" value="Click Me"/></a>

Happy Coding!!

Ravia