paulclift 0 Posted April 21, 2015 Report Share Posted April 21, 2015 (edited) 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 April 21, 2015 by paulclift Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 22, 2015 Report Share Posted April 22, 2015 There is a window.frames collection which you can use to loop through the frames on a page:https://developer.mozilla.org/en-US/docs/Web/API/Window/frames Quote Link to post Share on other sites
paulclift 0 Posted April 23, 2015 Author Report Share Posted April 23, 2015 Thanks justsomeguy, but this seems to be something which is in development and does not quite suit my needs in this specific case.. Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 23, 2015 Report Share Posted April 23, 2015 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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.