I managed to create a condition to detect anchor link, but after that how do I store the anchor link in my anchor_num variable, so that I can redirect the use to specific url?
<script type="text/javascript">
$(function(){
if(window.location.hash){
var anchor_num = "anchorString";
window.location = "#"+ anchor_num;
} else
{
//redirect to default page
}
});
</script>
By appending or changing hash the browser wouldn't refresh your page. You should call window.location.reload() after you've set the hash:
window.location = "#"+ anchor_num;
window.location.reload()