Jump to content
Sign in to follow this  
paulclift

Get iframe URL then use it dynamically

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Solved!

 

I just had to replace:

 

var current_url = document.getElementById("mainframe").src;
with
var current_url = document.getElementById("mainframe").contentWindow.location.href;

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...