2

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"

3
  • Not clear ya Mohamed .. From where you get the language? url , user browser? And what is the default href /en or /ar or its just www.facebook.com .. Also like I saw in your comment below the href is website.ae/ar/social#https:www.facebook.com/ar OR just www.facebook.com .. And you want this action just to the fb anchor..or you've another hrefs to do the same action with .. Please post the actual code .. and it will be better to show what you've tried so far Commented Jul 19, 2020 at 7:29
  • @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 Commented Jul 19, 2020 at 7:39
  • 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 lang="en" and lang="ar" to your <html> tag?? Commented Jul 19, 2020 at 7:51

2 Answers 2

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>

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for reply,but i want only url links no need link.href. it takes like this website.ae/ar/social#https:www.facebook.com/ar @sonetlumiere
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 this is what the OP said above after changing your answer to this.. I think your answer is correct if his <html> tag has a lang attribute
0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.