Wednesday 8 January 2014

Javascript : Page Redirection & Page Refresh

Javascript (JS) :

Page Redirection : 
                             It is a process by which URL which user typed for accessing page - X but
                             internally redirected to some other page
                       
Example:
type : www.fb.com
        it will redirect you to www.facebook.com

Example 1:

<head>
<script type="text/javascript">

   window.location="http://www.newpage.com";

</script>
</head>

Why Page - redirection is USEFUL ?

-For commercial website which have different product in different countries
-Publisher of website don't want to loose their visitors , so they buy all common domain which resembles
  their website name

You can set message also during Page-redirect :

Example :
<head>
<script type="text/javascript">

function Redirectme()
{
    window.location="http://www.newpage.com";
}

document.write("You will be redirected to main page in 5 sec.");
setTimeout('Redirectme()', 5000);
</script>
</head>

Page Refresh : 
                        It actually reload the page by calling reload method
                        Location.reload() method
                        if You pass location.reload(true) - will load page from server
                        otherwise it will reload from cache

No comments:

Post a Comment