The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Changing a link based on a user's language setting

4 posters

Go down

Solved Changing a link based on a user's language setting

Post by Ayushka Sun 10 Dec - 2:28

Hello!

I'm not sure if this is possible, but is there a way that a link would change from the original URL address to a different one for users who have a different language set in their options?
For example, I'd have a clickable icon in my forum's header that'd redirect you to some English website, but for my German users I'd like that icon to lead to a German website.
I hope I explained it properly and didn't confuse you lol
Forum version: AwesomeBB

Thank you in advance!


Last edited by Ayushka on Sun 10 Dec - 3:27; edited 1 time in total
Ayushka
Ayushka
New Member

Posts : 7
Reputation : 1
Language : en

https://help.forumotion.com/

Back to top Go down

Solved Re: Changing a link based on a user's language setting

Post by matt4116 Sun 10 Dec - 3:22

Hello, Ayushka.

are you referring to the url address of your forum? Here is a thread that might help you. hope you figure out the problem you are having. https://help.forumotion.com/t59451-frequently-asked-questions
matt4116
matt4116
New Member

Posts : 7
Reputation : 1
Language : english

Back to top Go down

Solved Re: Changing a link based on a user's language setting

Post by skouliki Sun 10 Dec - 8:08

Hello
You want an icon to be redirect to 2 pages depend the language?
I dont know if it possible by adding an onclick event to the image:
skouliki
skouliki
Manager
Manager

Female Posts : 15157
Reputation : 1696
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Changing a link based on a user's language setting

Post by Razor12345 Sun 10 Dec - 10:23

Good afternoon!

AP - Modules - Javascript codes management - Create new Javascript

Title: any
Placement: In all the pages
Javascript code:

Code:
jQuery(document).ready(function() {
  const language = navigator.language || navigator.userLanguage;
  const button = document.querySelector('.button__site');
  if (button) {
  button.addEventListener('click', function(e) {
    e.preventDefault();
    if (language === 'de-DE') window.location.href = 'https://www.example.com';
    else window.location.href = 'https://www.anotherexample.com';
  });
  }
});

Save.

Code:
const language = navigator.language || navigator.userLanguage;
- on this line we recognise the language of the user's browser.

Code:
const button = document.querySelector('.button__site');
- on this line we are looking for a button that responds to go to another site. My button has class
Code:
.button__site
. Yours may have a different class.

Code:
if (language === 'de-DE') window.location.href = 'https://www.example.com';
- If the user's browser language is German, the user will go to the https://www.example.com address when clicking on the button. Other users will be directed to the site at https://www.anotherexample.com



Changing a link based on a user's language setting Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1476
Reputation : 262
Language : Ukr, Rus, Eng
Location : Ukraine

skouliki, TonnyKamper and jucarese like this post

Back to top Go down

Solved Re: Changing a link based on a user's language setting

Post by skouliki Fri 22 Dec - 7:44

hello

if your request is completed/answered, please mark it as Solved.
skouliki
skouliki
Manager
Manager

Female Posts : 15157
Reputation : 1696
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Changing a link based on a user's language setting

Post by Razor12345 Tue 2 Jan - 10:19

Good afternoon!

It's been over two weeks now. We still have not received a reply from the author.
I am closing the topic and moving it to the archive.

If your problem is not solved - write me a private message and I will open this topic for further help.

Problem solved & topic archived.
Please read our forum rules: ESF General Rules


Changing a link based on a user's language setting Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1476
Reputation : 262
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum