I have a main page that has two iframes on it, a header and a body.
The following javascript is held in the code page for the header frame:
function help() { if (window.parent.bodyFrame.document.getElementById('grayOut').style.visibility == 'hidden') {window.parent.bodyFrame.document.getElementById('grayOut').style.visibility ='visible'; window.parent.bodyFrame.document.getElementById('help').style.visibility ='visible'; } else {window.parent.bodyFrame.document.getElementById('help').style.visibility ='hidden'; window.parent.bodyFrame.document.getElementById('grayOut').style.visibility ='hidden'; } }
I want this to toggle activating a ‘grayout’ div in the ‘bodyframe’ iframe.
It works fine in IE but not in Firefox. FF doesn’t seem to recognise the ‘window.parent.bodyFrame.document.getElementById’ element. Can anybody help with this? Does FF need to look at this differently somehow?
A simple ‘document.getElementById(‘foobar’) works fine in FF for an object on the same page.
So I did some tests and it looks like FF isn’t finding anything under ‘window.parent.’ at all! So what do I have to do?
I tryed window.parent.document.getElementById but it didnt work...
Using the above: IE says it can't find the object, I assume because the required object is within an iframe of the parent and not in the parent windows directly, and FF still dosn't recognise anything at all.
As I said FF dosn't seem to be getting past the window.parent.
part of the statment.
Using this insted of window produces the same results, e.g. IE works FF dosn't!
Hello Peter,
I tried that, and it doesn’t work on any browser... Presumable because the control I’m looking for isn’t actually in the parent page, but in the body of the page used by the bodyFrame iframe.
Apparently there is a bug in the later versions of Firefox that doesn’t let it see through frames by their name. So the ‘bodyFrame’ object wasn’t followed.
I got this working on all the browsers I tested by using the frames number instead of using the id name e.g.
function help()
{
if (window.parent.frames[1].document.getElementById('grayOut').style.visibility == 'hidden')
Garry_G
Member
113 Points
85 Posts
window.parent. javascript problem with Firefox
Feb 21, 2012 12:29 PM|LINK
I have a main page that has two iframes on it, a header and a body.
The following javascript is held in the code page for the header frame:
function help()
{
if (window.parent.bodyFrame.document.getElementById('grayOut').style.visibility == 'hidden')
{window.parent.bodyFrame.document.getElementById('grayOut').style.visibility ='visible';
window.parent.bodyFrame.document.getElementById('help').style.visibility ='visible';
}
else
{window.parent.bodyFrame.document.getElementById('help').style.visibility ='hidden';
window.parent.bodyFrame.document.getElementById('grayOut').style.visibility ='hidden';
}
}
I want this to toggle activating a ‘grayout’ div in the ‘bodyframe’ iframe.
It works fine in IE but not in Firefox. FF doesn’t seem to recognise the ‘window.parent.bodyFrame.document.getElementById’ element. Can anybody help with this? Does FF need to look at this differently somehow?
A simple ‘document.getElementById(‘foobar’) works fine in FF for an object on the same page.
So I did some tests and it looks like FF isn’t finding anything under ‘window.parent.’ at all! So what do I have to do?
Muhammad Fak...
Contributor
2268 Points
511 Posts
Re: window.parent. javascript problem with Firefox
Feb 21, 2012 12:33 PM|LINK
Use window.parent.document.getElementById instead window.parent.bodyFrame.document.getElementById
If you feel it helps, Mark as answered so that it can help others to find solution.
For Any further questions, please contact me.
Garry_G
Member
113 Points
85 Posts
Re: window.parent. javascript problem with Firefox
Feb 21, 2012 02:29 PM|LINK
I tryed window.parent.document.getElementById but it didnt work...
Using the above: IE says it can't find the object, I assume because the required object is within an iframe of the parent and not in the parent windows directly, and FF still dosn't recognise anything at all.
As I said FF dosn't seem to be getting past the window.parent. part of the statment.
E.g. 'bodyFrame' is the name of my second iframe.
The top-page code is:
<HTML>
<HEAD>
<TITLE>test</TITLE>
<LINK rel="stylesheet" type="text/css" href="style.css" />
</HEAD>
<BODY onLoad="javascript: document.body.style.overflow='hidden';" bgcolor="#332222">
<IFRAME src="asp/menubar.asp" width="100%" height="25px" scrolling="no"
marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0"
style="position:absolute; top:0px;">
</IFRAME>
<IFRAME id="bodyFrame" src="asp/main.asp" width="100%" height="95%" scrolling="auto"
marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0"
style="position:absolute; top:26px;">
</IFRAME>
</BODY>
</HTML>
Muhammad Fak...
Contributor
2268 Points
511 Posts
Re: window.parent. javascript problem with Firefox
Feb 21, 2012 03:39 PM|LINK
Use this instead of window
If you feel it helps, Mark as answered so that it can help others to find solution.
For Any further questions, please contact me.
raju dasa
Star
14392 Points
2447 Posts
Re: window.parent. javascript problem with Firefox
Feb 21, 2012 04:24 PM|LINK
HI,
check this site:
http://msdn.microsoft.com/en-us/library/ms537459%28v=vs.85%29.aspx
rajudasa.blogspot.com || blog@opera
Smith Peter
Member
142 Points
52 Posts
Re: window.parent. javascript problem with Firefox
Feb 22, 2012 04:31 AM|LINK
Hi,
Try this:
function help() { if (window.parent.document.getElementById('grayOut').style.visibility == 'hidden') {window.parent.document.getElementById('grayOut').style.visibility ='visible'; window.parent.document.getElementById('help').style.visibility ='visible'; } else {window.parent.document.getElementById('help').style.visibility ='hidden'; window.parent.document.getElementById('grayOut').style.visibility ='hidden'; } }Garry_G
Member
113 Points
85 Posts
Re: window.parent. javascript problem with Firefox
Feb 22, 2012 08:11 AM|LINK
Hello Muhammad Fakhr Elden Sam,
Using this insted of window produces the same results, e.g. IE works FF dosn't!
Hello Peter,
I tried that, and it doesn’t work on any browser... Presumable because the control I’m looking for isn’t actually in the parent page, but in the body of the page used by the bodyFrame iframe.
Garry_G
Member
113 Points
85 Posts
Re: window.parent. javascript problem with Firefox
Feb 22, 2012 08:37 AM|LINK
I found out why this isn’t working!
Apparently there is a bug in the later versions of Firefox that doesn’t let it see through frames by their name. So the ‘bodyFrame’ object wasn’t followed.
I got this working on all the browsers I tested by using the frames number instead of using the id name e.g.
function help()
{
if (window.parent.frames[1].document.getElementById('grayOut').style.visibility == 'hidden')
{window.parent.frames[1].document.getElementById('grayOut').style.visibility ='visible';
window.parent.frames[1].document.getElementById('help').style.visibility ='visible';
}
else
{window.parent.frames[1].document.getElementById('help').style.visibility ='hidden';
window.parent.frames[1].document.getElementById('grayOut').style.visibility ='hidden';
}
}
P.s. it also works when using this instead of window as you are pretty much saying the same thing.
It also works when just using parent.frames... so it looks like it's the frame name that's the important bit, and not the caller type.