Solution 1 :

Maybe this helps

let lang = document.documentElement.lang;
console.log(lang);

let link = document.getElementById("fb");

if(lang == 'ar'){
    link.href += '/ar'
} else if(lang == 'en'){
    link.href += '/en'
}
<a id="fb" href= "www.facebook.com">Facebook</a>

Solution 2 :

You can try this =>

<html lang="en">
<head>
    <title>Document</title>
</head>
<body>
    <a id = "ar">Facebook AR</a>
    <a id = "en">Facebook EN</a>
    <script>
        var ar = document.getElementById("ar").setAttribute("href", "www.facebook.com/ar");
        var en = document.getElementById("en").setAttribute("href", "www.facebook.com/en");
    </script>
</body>
</html>

but it is better to use like this, if not it may be some console errors

var ar = document.getElementById("ar") ? document.getElementById("ar").setAttribute("href", "www.facebook.com/ar") : null;
var en = document.getElementById("en") ? document.getElementById("en").setAttribute("href", "www.facebook.com/en") : null;

Problem :

example <a id = "fb" href= "#">Facebook</a>

Actually i want if page is Arabic it should be like this
href = "www.facebook.com/ar"
if page is English href = "www.facebook.com/en"

Comments

Comment posted by Mohamed-Yousef

Not clear ya Mohamed .. From where you get the language? url , user browser? And what is the default href

Comment posted by Mohamed Abubakkar

@Mohamed-Yousef yes brother, let me tell you . i have used umbraco library for language change and the default language is arabic i can’t put my fb links into anchor tag because i have two different fb pages for both languages ,my question is i want to create once user click the fb in arabic it should go to my arabic facebook page or if english it should go to english facebook page

Comment posted by Mohamed-Yousef

You mean you use our.umbraco.com CMS? and it handle a language for you? right? Sorry this is my first time I hear about umbraco .. anyway Is the umbraco add

Comment posted by website.ae/ar/social#https:www.facebook.com/ar

Thanks for reply,but i want only url links no need link.href. it takes like this

Comment posted by Mohamed-Yousef

i have two different fb pages for both languages ,my question is i want to create once user click the fb in arabic it should go to my arabic facebook page or if english it should go to english facebook page

By

Leave a Reply

Your email address will not be published. Required fields are marked *