Redirecting visitors with Javascript is straightforward. The simplest way is to use one of the methods given below.
location.href Method
Including the following script will immediately redirect visitors to the URL entered.
<script type="text/javascript">
location.href='http://it-aspnet.blogspot.com';
</script>
location.href='http://it-aspnet.blogspot.com';
</script>
location.replace Method
Including the following script will immediately redirect visitors to the URL entered.
<script type="text/javascript">
location.replace('http://it-aspnet.blogspot.com/');
</script>
location.replace('http://it-aspnet.blogspot.com/');
</script>
The difference between location.href and location.replace
The difference between location.href and location.replace is that location.replace creates a new history entry on the visitor's browser meaning that if they hit the back button, they can get in a 'redirection loop' which is usually undesirable and may have unwanted side effects.






No comments:
Post a Comment