• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Inserting Javascript in Muse CC

New Here ,
Jan 16, 2017 Jan 16, 2017

Copy link to clipboard

Copied

Hi everyone.

As I develop multi-lingual web sites, I find it practical when the visitor, upon changing the language, doesn't find himself at the index page to re-do all the work to get to the page where he was.

For that I use a different directory for each language.

I have a script that helps me change the directory dynamically. Here it is:

var lang_arr = ['en', 'de', 'fr', 'it', 'tr']; // define here available languages

function change_url(new_lang) {

if (!inArray(new_lang, lang_arr)) return false;

var url_pieces = document.location.pathname.split('/');

for (i = 0; i < url_pieces.length; i++) {

if (inArray(url_pieces, lang_arr)) {

url_pieces = new_lang;

window.location.href = document.location.origin + url_pieces.join('/') + document.location.search;

}

}

}

function inArray(needle, haystack) {

var length = haystack.length;

for (var i = 0; i < length; i++) {

if (haystack == needle) return true;

}

return false;

}

I have put that in the HTML for <head> of the page properties in the master page.

I then put a link on the page with the following in the Hyperlinks:

javascript:;" onclick="change_url('en')"

Why doesn't work? What am I missing? Any suggestions?

Jim

Views

2.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jan 16, 2017 Jan 16, 2017

I hope you use tags <script></script>?

....Try to put your script before </body>.  Use the following file.

Dropbox - CodeInsert.mucow

Insert your code.

03901f34c4.png

Save the file and place it on the page. ( File / Place)

Votes

Translate

Translate
Guide ,
Jan 16, 2017 Jan 16, 2017

Copy link to clipboard

Copied

I hope you use tags <script></script>?

....Try to put your script before </body>.  Use the following file.

Dropbox - CodeInsert.mucow

Insert your code.

03901f34c4.png

Save the file and place it on the page. ( File / Place)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

Thanks. In fact as you put it out, I had forgotten the <script> and </script> tags. It now works just fine.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

LATEST

hi, can you help me i need something like you, but i dont know how to do that if you can upload a text about it to learn step by step plz

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines