Redirection in javascript

Javascript also gives us facility to redirect the user to a webpage or website. Also it's easy to learn redirection in javascript. It is just one line code that needed to embed in a function of javascript to redirect the user.

Let's see how to perform redirection in javascript. I am going to make a custom function redirectuser().

<script language="javascript" type="text/javascript">
function redirectuser()
{
window.location="www.google.com";
}
</script>

So this is the function redirectuser() is capable of redirecting user from one one webpage to another or redirecting user from one website to another. In the above example I am redirection user to google.com.

Now it’s up to you where you will call this custom function. I am going to call this function over button's onClick event. Let's have a look over how to do this.

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

So this is the way to perform redirection in javascript using custom made function.

0 comments: