With the below script I was trying to load the output of the variable "url" in the browser on clicking the anchor tag, while executing it shows the expected result path in the alert box but it loads the path mentioned in the anchor tag. I want to load the output path in the browser's same tab. please help me to solve this.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("a").on('click', function(){
var reqURL = window.location.href;
var hrefVal = $(this).attr('href');
var url;
if(hrefVal.indexOf("http")== -1){
if(reqURL.indexOf("/ca-en") != -1){
url="http://www.mywebsite.com/site2"+hrefVal;
}else if(reqURL.indexOf("/ca-fr")> -1){
url="http://www.mywebsite.com/site3"+hrefVal;
}else{
url="http://www.mywebsite.com"+hrefVal;
}
alert(url);
window.open(url,"_self");
}
});
});
</script>
</head>
<body>
<ul>
<li>
<a class="category" href="/home.html">home<span class="icon plus"></span></a>
<ul class="submenu">
<li><a href="/home/abc.html">abc</a></li>
<li><a href="/home/xyz.html">xyz</a></li>
<li><a href="/home/tam.html">tam</a></li>
</ul>
</li>
</ul>
</body>
</html>