Jump to content

Update content on iframe inside iframe

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

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.

  • Create New...