Jump to content

Update content on iframe inside iframe


paulclift
 Share

Recommended Posts

Hey all,

 

I have a language switch on a website which updates the displayed language in the main iframe. However, I am also using fancy box, which pops up out of the iframe, and is therefore an iframe within an iframe. I change the language to be displayed with the following code:

 

function setlang(lang) {

var i;
var len;
var list;
var ifr = document.getElementById('mainframe');
var cw = (ifr.contentWindow || ifr.contentDocument);
list = cw.document.getElementsByClassName('langdiv');
for (i=0, len=list.length ; i<len ; i++){
list.style.display = 'none';
}
list = cw.document.getElementsByClassName(lang);
for (i=0, len=list.length ; i<len ; i++){
list.style.display = 'inline-block';
}
}
.....and here is the HTML:
<input id="EN" name="view" type="radio" onclick="setlang('EN'); sessionStorage.setItem('language', 'EN');">
<input id="DE" name="view" type="radio" onclick="setlang('DE'); sessionStorage.setItem('language', 'DE');">
<input id="FR" name="view" type="radio" onclick="setlang('FR'); sessionStorage.setItem('language', 'FR');">
Could someone please help me make this work whereby the iframe is not necessarily called 'mainframe' but is simply *any* iframe that has multiple languages? I suspect that this will necessitate converting most of my vars into arrays, something which I am not really confident about doing on my own. Thanks!
The website in question is: www.neuverband.ch
Edited by paulclift
Link to comment
Share on other sites

That was implemented in DOM level 0, which was nominally part of Netscape and IE 3 if you care to look up when those were released. It is supported in all major browsers. That's how you loop through every frame on the page. You can also use document.getElementsByTagName to get all iframes if you want to do it that way.

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
 Share

×
×
  • Create New...