Viewing How to execute JavaScript on clicking a button?

How to execute JavaScript on clicking a button?



User: Oliver O. 7 years ago
I would like to add a button which allows the user to switch from the German to the English website and vice versa.

I don't know how to do this in Everweb: A British flag button, when clicked then the user sees the current page in German. Therefor I parse the uri and change path /en/ to /de/.

I found this code:

HTML:

<span onclick="SwitchLang()">View [Some other Language]</span>

java script:

function SwitchLang() {
if(window.location.href.indexOf("/en/") != -1)
window.location.href = window.location.href.replace("/en/", "/de/");
else if(window.location.href.indexOf("/de/") != -1)
window.location.href = window.location.href.replace("/de/", "/en/");
}

I guess I only would need this part of it:

window.location.href = window.location.href.replace("/en/", "/de/");

What would I have to do in order to execute java script, when clicking a picture or text?
User: Roddy 7 years ago
If you have two versions of your site - one in English and the other in German - the easiest way is to use the method outlined in THIS instructional video.

If you intend switch the language dynamically without reloading the page, that's a different ballgame!

If you need to make your website available in multiple languages and don't have the time to create multiple versions you could try using the Google Translate widget for a quick and dirty solution.

-------------------------------
Roddy

Website: http://everwebwidgets.com
Contact: http://everwebwidgets.com/ewWidgets-home/contact.html
NOTE: I am an EverWeb user and NOT affiliated with EverWeb! Any opinions expressed in this forum are my own.
User: Oliver O. 7 years ago
Thank you for the response. I see now that I need to ask more specifically: do. you have an example on how to implement and execute java script when clicking on a picture, for Everweb?
User: Roddy 7 years ago
Exactly what do you want to happen when the image is clicked?

-------------------------------
Roddy

Website: http://everwebwidgets.com
Contact: http://everwebwidgets.com/ewWidgets-home/contact.html
NOTE: I am an EverWeb user and NOT affiliated with EverWeb! Any opinions expressed in this forum are my own.
User: Oliver O. 7 years ago
I have two different websites with the same structure, one in a subfolder /de/ and the other in /en/

I have a index.php file in place which forwards the user to the German website if his setting is German, otherwise to English.

Now I want to give the user the possibility to switch to the other language, no matter on which page he is, and end up on the same page of the other language's website.

I thought I could achieve this with java script like this one:

function SwitchLang() {
window.location.href = window.location.href.replace("/en/", "/de/");
}

I do not wish to implement all languages in one Everweb project, but rather have separate projects with different language but identical structure. Different people can then work individually on one language project.

Does that make sense?
User: Roddy 7 years ago
If you want the vistor to make the choice of switching from one language to the other, all you need it a "flag" button link to the page in the other language. There's no need to use java script.

-------------------------------
Roddy

Website: http://everwebwidgets.com
Contact: http://everwebwidgets.com/ewWidgets-home/contact.html
NOTE: I am an EverWeb user and NOT affiliated with EverWeb! Any opinions expressed in this forum are my own.
User: Oliver O. 7 years ago
Yes I am aware of this possibility.

However, instead of static linking with hardcoded addresses on each page, I prefer to find a flexible, programmable solution. A few lines of code in the header of a Master page, this is what I am going to do.

I have hoped that someone of Everweb might answer here and give me a hint.

There must be a way, and I will find it.
User: Oliver O. 7 years ago
Just as a proof of concept:

https://xojopro.com/en/index.html

I have 2 index.html pages, one in the /en folder and the other in the /de folder.
The java script parses the url and replaces en with de (and back)

index.html looks like this:



Now I just have to find out on how to implement this with a Everweb Masterpage

Last edit 7 years ago
User: Roddy 7 years ago
Use an HTML Snippet widget to insert the HTML for the button (or image link) and the script. See THIS page unde HTML Snippet for info.

-------------------------------
Roddy

Website: http://everwebwidgets.com
Contact: http://everwebwidgets.com/ewWidgets-home/contact.html
NOTE: I am an EverWeb user and NOT affiliated with EverWeb! Any opinions expressed in this forum are my own.
User: Oliver O. 7 years ago
Yes, exactly! Your help pages have been very useful to me and I have already implemented it that way. It works! Thanks a lot!


Post Reply
You must login or signup to post.