Log in

View Full Version : HTML button with link



juliememe
01-16-2012, 12:18 PM
Hi
I need to create a HTML button that leads me on click to a website (i.e. google.de)

can anybody send me the code?

Thank you (I am a beginner)

keyboard
01-16-2012, 09:52 PM
Welcome juliememe to the forums



<input type="button" onclick="location.href('http://www.google.com');" value="Redirect">



or using a function


This should go in the <head> </head> section of your page.


<script type="text/javascript">
<!--
function redirect() {
window.location = "http://www.google.com/"

}
//-->
</script>


This should go in the <body> </body>


<input type="button" onclick="redirect()" value="Redirect">

Keyboard1333

coothead
01-17-2012, 08:16 AM
Hi there juliememe,

and a warm welcome to these forums. ;)

try it like this...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">

<title></title>

<style type="text/css">
#mybutton {
color:#000;
text-decoration:none;
}
</style>

</head>
<body>

<div>
<a id="mybutton" href="http://www.google.com/" title="link to google.com">
<button>google</button>
</a>
</div>

</body>
</html>

coothead

[Nicolas]
01-17-2012, 11:12 PM
<a href="http://google.com/"><button>Your First Button</button></a>
Or:

<button onclick="window.location='http://google.com';">Your First button</button>

alexey21
01-27-2012, 12:03 PM
This is your code:


<form method="LINK" action="http://yourlink.com">
<input type="submit" value="Button with link">
</form>


_________________________________________________________________

A free escort website (http://escortsite.com) solution for both independent escorts and agencies.

january
01-27-2012, 01:05 PM
you can do it in various ways:

Using the below source will allow you to create a push button link. change the URL http://www.yoursite.com to the web page you wish to open.

<FORM>
<INPUT TYPE="BUTTON" VALUE="Home Page" ONCLICK="window.location.href='http://www.yoursite.com'">
</FORM>

other one is:
remove spaces and carriage returns from code in quotes


<form>
<input
type="button"
src="image-url"
onClick="Javascript: window.open( URL, "_self", , True)
>
OR

onClick="Javascript: window. location. replace( URL )

</form>

A simple javascript can also fulfill your need:


function Hi()
{
alert("psst");
}


function addRowToTable()
{
var tbl = document.getElementById('secondtable');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
var cell1 = row.insertCell(0);

var buttonnode= document.createElement('input');
buttonnode.setAttribute('type','button');
buttonnode.setAttribute('name','sal');
buttonnode.setAttribute('value','sal');
cell1.appendChild(buttonnode);
buttonnode.attachEvent('OnClick',Hi());

}

Complete code:


<html>
<head><title></title>
<script type="text/javascript" language="javascript">
<!-- Hide from browsers without javascript

function g()
{
alert("you clicked?");

}

window.onload=function()
{
var buttonnode= document.createElement('input');
buttonnode.setAttribute('type','button');
buttonnode.setAttribute('name','button'+3);
buttonnode.setAttribute('value','sal');
buttonnode.setAttribute('onclick', function(){alert('Clicked')});
document.getElementsByTagName("body").item(0).appendChild(buttonnode);
};

// End hiding -->
</script>
</head>
<body>

<div>some text</div>

</body>
</html>

Hope this serves your purpose.
Thanks