How to Get the current url and redirect to other url(case:button click english to arabic screen using parameter in url) using jquery,mvc,c#
<a class="btn btn-icon btn-clean btn-lg w-40px h-40px btnlang" id="btnlang" > Change Lang </a>
sample url: https://localhost:44310/Claims/AddClaim?lang=en
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('.btnlang').click(function () {
debugger;
var pageURL = $(location).attr("href");//gets the current url
var baseaddress = pageURL.substring(0, pageURL.indexOf('?'));//get the base address before '?'
var tech = getUrlParameter('lang');//gets the parameter using parameter name i.e,lang
if (tech == "en") {
location.href = baseaddress + "?lang=ar";
} else if (tech == "ar") {
location.href = baseaddress + "?lang=en";
}
});
var width = screen.width,
height = screen.height;
if (width <= 600) {
$('#kt_aside').removeClass('aside-overlay');
}
});
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
};
</script>
Comments
Post a Comment