Trying to implement a script that loads the output of the variable "url" in the browser when clicking an anchor tag. The alert box displays the expected result path, but the link opens the path mentioned in the anchor tag. Seeking assistance in resolving this issue.
<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>