Thursday, June 13, 2013

How to navigate forward and back to the pages using JavaScript

Follow the steps to navigate forward and back to the pages using JavaScript.
<html>
<head>
<script language='JavaScript' type='text/javascript'>
function goBack() {
     window.history.back();
}
</script>
</head>
<body>
<input type='button' name='back' value='Go Back' title='Click here to go back' onClick='goBack()'>
</body>
</html>
When the user click on the button it will go back to last visited page which means previous page.
We can write this code in another way.
<script language='JavaScript' type='text/javascript'>
function goBack() {
     window.history.go(-1);
}
</script>
This script is also works same as the above script. This is the same as the back button functionality of the browser. Here '-1' represents the previous page.

And we can use this script to load the next URL in in the history list.
<html>
<head>
<script language='JavaScript' type='text/javascript'>
function goForward() {
     window.history.forward();
}
</script>
</head>
<body>
<input type='button' name='forward' value='Go Forward' title='Click here to go Forward' onClick='goForward()'>
</body>
</html>
This is the same as the forward button functionality of the browser.

Thank you...

Wednesday, June 12, 2013

How to do HTTP redirect to a URL using JavaScript

Follow the simple steps to do HTTP redirect to a URL using JavaScript.
<html>
<head>
<script type='text/javascript'>
forwardUrl(); // calling the function to redirect
function forwardUrl() {
     window.location.href = 'http://www.phpboyz.com/page1.php';
}
</script>
</head>
<body></body>
</html>
Change the URL to your url to forward. And call the function to forward.

And we can send the parameters along with the url using this script also.
<script type='text/javascript'>
var value1 = 10;
var value2 = 'testing';
     window.location.href = 'http://www.phpboyz.com/page1.php?param1='+value1+'&param2='+value2;
</script>
This script will forward from current page to requested URL location along with the 2 GET parameters param1 and param2. we can use this 2 parameters where ever we need.
Use $param1 = $_GET['param1'] and $param2 = $_GET['param2'] to get the values in the page1.php.

Thank you...