Jump to content

Change image depending on visitor country


uworlds

Recommended Posts

Hello,  

I would be very appreciative for any advice.

I want to create a container on a Web page which inserts a clickable image to a variable URL, depending on the country the visitor is from. 

For example if a visitor is from China then the container imports a specific image with clickable URL from a repository of images and associated URLs.   A random selection is fine, but for now I just want to get it working with a single clickable image. 
 

rhsnk you !   

Link to comment
Share on other sites

It's not easy and Javascript alone wouldn't be able to do it. You need a server-side language and a database or access to an API.

There are two possible approaches:

  1. Get the country from the user's IP address by using an IP address database or API. This can only be done by a server-side language.
  2. Get the user's coordinates with the geolocation API and use a database or API to determine which country the coordinates belong to.

Both of these would take a few hours of work to complete, so it's not something I can write in a forum post.

 

If you want to avoid this complication, the best solution is to ask the user what country they're in, using a dropdown or an autcomplete text field.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...