Pages

Tuesday, August 26, 2014

Redirect using javascript in same tab

There are two ways to achieve this:
location.assign();
assign() simply reloads the page with given url.


location.replace();
replace()  doesn't save current page in session history so back button will not be available to navigate back..


<html>
<head>
<script>
function assignx()
{
                       //assign simply reloads the page with given url
document.location.assign('http://dirtycodes.blogspot.com/');
}
function replacex()
{
                        //replace()  replaces the history so back button will not work
window.location.replace("http://dirtycodes.blogspot.com/");
}
</script>        
    </head>
<body>
<a href="javascript:void(0)" onclick="assignx();">ASSIGN</a>
</br>
<a href="javascript:void(0)" onclick="replacex();">REPLACE</a>              
               
    </body>
</html>

No comments:

Post a Comment