I have wordpress website using GTranslate. As I made Chinese version of the website, I want that when someone click on ‘Chinese’ in drop down menu of GTranslate, I actually send him to new Chinese website. GTranslate plugin developer told me I need to create Javascript onclick event for that. how can i do this please?
When someone select this in drop down of GTranslate:
Chinese (Simplified)
I need to send them to a new URL.
Can you please show me Javascript and how to implement it – where to place script?
Thanks a lot.
2
Answers
add the
onclick="newPageFunction(url)"
to the chinese button in the dropdown list then try this functionYou should pace the new page url in url variable
Here I present a slightly more comprehensive a large list of options in the
<select>
and an arraylanguages
.Your plugin probably has similar values in the select list but that reference was not provided so I give this generic answer instead.
When a language from the list matches an option and the language
isActive
is true, then we add an active class to the option and show it via the CSS; effectively hiding all the non-active from the list.You can modify the JavaScript
languages
array to activate whichever you have now created on your site – which might even be done somewhat generically.Now all you have to do is activate languages and put in a proper URL (OR a function to construct a URL generically from your
url
value which would be my suggestion.