Click to See Complete Forum and Search --> : document.getElementById('').innerHTML in another frame
druss
01-24-2004, 11:52 PM
i am trying to write into the frameset with a page that belongs to that frameset by using the document.getElementById method. so far all its telling me is that it is null or not an object?
This is the code that i have tried.
parent.document.getElementById('no_frames').innerHTML= "<script>parent.mainFrame.finished()</script>";
i know its something like that yet i cannot pinpoint what it is.
Thanks in advanced
Goz
Pittimann
01-25-2004, 12:43 AM
Hi!
Reading your code snippet, I rather have the impression that you want to run a function instead of playing with innerHTML. Could you describe, what you want to happen?
Cheers - Pit
rrivas
10-28-2008, 12:47 PM
Although this is a almost 5 year old post I'd like to know the answer as to why this did not work. I am currently trying to get an iframe to change some content on the parents window so the code I have is similar to the original post except that I want to make innerHTML='message'.
Thanks.
toicontien
10-28-2008, 01:26 PM
If the document in the IFRAME comes from the same domain as the document in the parent window, then the parent.document.getElementById() function should work. If they are from different domains, browsers will block any attempt at accessing the window object of either the IFRAME from the parent window, or the parent window from the IFRAME.
rrivas
10-28-2008, 01:40 PM
What I am attempting to do is basically have a link that would change a div in the parent window to just say "hello". Both files are located on the same domain.
The parent window has
<div id='msgCtr'>Hi There</div>
and the child iframe has
<a href="javascript:parent.document.getElementById('msgCtr').innerHTML='hello';">
Click here to change parent URL </a>
When I click the link I get an error saying:
Line: 1
Char: 1
'parent.document.getElementById(...)' is null or not an object
Thanks.
toicontien
10-28-2008, 02:32 PM
Your code appears correct. Something else must be afoot. In the parent window, is there more than one tag whose Id is "msgCtr"? Is there another tag in the parent window whose name is "msgCtr"?
rrivas
10-29-2008, 11:27 AM
Does this code snippet have problems on IE/FF because I tried it on safari and it works fine but on IE/FF it does something weird.
Example: http://www.cs.ucr.edu/~rrivas/frames/iframe.html
Thanks.
rrivas
10-29-2008, 12:46 PM
I figured out why I had the problem from the post before which is not to use links to change an aspect of a parent window.
What I am attempting to do is make a tool that would create a list within the iframe and the iframe would control a message on the parent window calling the iframe. The original plan was to have a hover function that would display the details of the item the user is hovering in the section that now displays "Hi There". As of now when I run it at http://www.exteres.net/EXCv3/IPR_Module/iframe.php it will give me a "parent.document.getElementById(...) is null or not an object".
The code that I am using to control this is:
parent:
<div id='BLAH'>Hi There</div>
<iframe id='notthis' src="./iframetest.php"></iframe>
child:
<script language="javascript">
function test()
{
parent.document.getElementById('BLAH').innerHTML='Hello.';
}
</script>
<button onClick="test()">Click Me</button>
I've tried several things, some that I dont think are even legal statements such as "window.parent..." but nothing seems to work. I dont know if this is an IE7 thing or just me missing something. I would appreciate any help. Thanks.
toicontien
10-29-2008, 01:26 PM
Given the link above, you need to do this instead:
<a href="#" onclick="parent.document.getElementById('msgCtr').innerHTML='hello'; return false;">Click here to change parent Message</a>
This ensure that nothing happens when the user clicks on the link, except for what the onclick event handler does.
rrivas
10-29-2008, 01:44 PM
I added that link to my overall test and it returns the same problems. I did not know you could do "return false" on a link though would have saved me a ton of trouble on other small projects.
toicontien
10-29-2008, 01:47 PM
Do you have your code posted online somewhere? I tried the link you gave above but it has the same code. Can you post the code you are using now?
rrivas
10-29-2008, 02:56 PM
http://www.exteres.net/EXCv3/IPR_Module/iframe.php
toicontien
10-29-2008, 03:04 PM
Hm. Firefox is saying that parent.document is undefined. ... not really sure why. I whipped up a quick test page with an IFRAME and parent is a window reference:
temp.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<iframe src="test.html"></iframe>
</body>
</html>
test.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!-- begin hiding
alert(parent.document);
// end hiding -->
</script>
</head>
<body>
</body>
</html>
rrivas
10-29-2008, 04:19 PM
I added the command "alert(parent.document);" to the Click Me button and it shows as undefined. I'm not sure why but I can only conclude its because of the PHP code running behind it. I have am using the mapquest api for some numbers and I had to wait for the php portion of the script to receive the mapquest info in order to output it. If I put that alert at the end of that php script in an echo it works fine. Why this is...no idea. I'll leave the alert at the end of the script so you can see what I mean.
For clarification the alert at startup is from the echo and the button at the end of the load thats titled "Click Me" is undefined.
Thanks.