Jump to content

Get iframe URL then use it dynamically


paulclift

Recommended Posts

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 by paulclift
Link to comment
Share on other sites

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

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 by paulclift
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...