Friday, April 26, 2013

Go to another page using javascript

window.location.href = url; 

This line of code can be used to go to another page without using <a> (anchor tag). This line of code is placed in some javascript function and the function is called on an event.


Example:

<!doctype html>
<html>
<head>
<title>test</title>
<script>
function goto(){
window.location.href="http://www.google.com";
}
</script>
</head>
<body>
<button onclick="goto();">on google</button>
</body>
</html>

No comments:

Post a Comment