paulclift Posted November 27, 2013 Share Posted November 27, 2013 (edited) Hey all, This will be easy for some of you but it's making me pull my hair out. Here is the relevant URL: http://www.neuverband.ch/index_TEMP.html I want to set the 'choose language' switch in the top right so that it will jump to the same page, in the chose language, as the one which is currently loaded... e.g. if the 'about-us' page is loaded and you switch language, rather than going back to the main page, it should go to 'about-us' in the new language. The site is organised in this way: page-name-in-English + _ + LANGUAGE + .html so, the possible URLs for 'about-us' are: about-us_EN.html about-us_DE.html about-us_FR.html about-us_IT.html As I see it, to do this, it's just a simple three-step process: 1. Store current iframe URL as variable 'X' - ALREADY DONE 2. Remove suffix _LANG from X and store as variable 'Y' - ALREADY DONE 3. set links in the 'choose-language-switch' to Y_EN, Y_DE, Y_FR & Y_IT - THIS PART IS WHAT I AM TRIPPING UP ON All of this will happen in the index_TEMP.html because the whole site displays with inline frames (id="mainframe"). PLEASE HELP! Paul Edited November 27, 2013 by paulclift Link to comment Share on other sites More sharing options...
paulclift Posted November 27, 2013 Author Share Posted November 27, 2013 (edited) g Edited November 27, 2013 by paulclift Link to comment Share on other sites More sharing options...
justsomeguy Posted November 27, 2013 Share Posted November 27, 2013 You're doing everything when the page loads, that code should be running when the button gets clicked. The button only needs to pass the language suffix to the function. The function should get the current URL of the iframe and replace the language suffix with the one passed to the function, and then set the new src for the iframe. Link to comment Share on other sites More sharing options...
paulclift Posted November 27, 2013 Author Share Posted November 27, 2013 (edited) Thanks for the response. I was just working on this now.. it works partly but the 'mainframe.src' which is reported to javascript function never changes, even when a different page is loaded..... I don't quite get why; is it because I specify the src in the 'inline' object itself? <!--SWITCH STUFF--!> <div class="switch> <input id="english" name="view" type="radio" checked onclick="change_language('EN')"/> <input id="deutsch" name="view" type="radio" onclick="change_language('DE')"/> </div> <!--IFRAME STUFF--!> <div id="iframe"> <iframe name="mainframe" id="mainframe" src="home_EN.html"></iframe> <script> function change_language(new_language){ var current_url = document.getElementById("mainframe").src; current_url = current_url.substring(current_url.lastIndexOf("/") + 1); var new_url = current_url.split ('_')[0] + '_' + new_language + '.html'; /* replaces the language suffix */ document.all.mainframe.src = new_url; /* sends new URL to 'mainframe' */ } </script> </div> Edited November 27, 2013 by paulclift Link to comment Share on other sites More sharing options...
paulclift Posted November 27, 2013 Author Share Posted November 27, 2013 Solved! I just had to replace: var current_url = document.getElementById("mainframe").src; with var current_url = document.getElementById("mainframe").contentWindow.location.href; Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now