jayh99
asked on
Javascript from IFrame write to DIV in page
Can someone help me writing from an IFRAME to the div in my parent page. I am trying the code below, but I get a js error when it runs. I am guessing that if it is possible, the error is in the document.getElementById(id );. The script is in my IFRAME, and the DIV is in my parent page. Thanks in advanced for the help.
function writit(text,id)
{
if (document.getElementById)
{
x = document.getElementById(id );
x.innerHTML = '';
x.innerHTML = text;
}
else if (document.all)
{
x = document.all[id];
x.innerHTML = text;
}
else if (document.layers)
{
x = document.layers[id];
text2 = '<P CLASS="testclass">' + text + '</P>';
x.document.open();
x.document.write(text2);
x.document.close();
}
}
function writit(text,id)
{
if (document.getElementById)
{
x = document.getElementById(id
x.innerHTML = '';
x.innerHTML = text;
}
else if (document.all)
{
x = document.all[id];
x.innerHTML = text;
}
else if (document.layers)
{
x = document.layers[id];
text2 = '<P CLASS="testclass">' + text + '</P>';
x.document.open();
x.document.write(text2);
x.document.close();
}
}
ASKER
Thanks for the quick response, I tried parent.getElementById, but didn't try parent.document. I'll give it a try tomorrow morning and let you know if it works. Thanks again.
ASKER
I get the following error:
'x' is null or not an object
'x' is null or not an object
ASKER
I just noticed that when I go put
window.parent.name, it gives me a layer within my iFrame. Is there a way to do like a top.getElementById or a way to find the outermost layer?
window.parent.name, it gives me a layer within my iFrame. Is there a way to do like a top.getElementById or a way to find the outermost layer?
ASKER
*sorry about the broken english in that last response, it was a series of copy/pastes gone wrong. I meant:
alert(window.parent.name);
gives me a layer within the iFrame.
alert(window.parent.name);
gives me a layer within the iFrame.
you should try top.getElementById then.
ASKER
No luck with the top.getElementById
I was wrong when I wrote:
//
alert(window.parent.name);
gives me a layer within the iFrame.
//
That is actually the name of my iFrame. I have tried the following code, but it didn't work either.
x = window.parent.parent.getEl ementById( 'Results') ;
alert(x.innerHTML);
I was wrong when I wrote:
//
alert(window.parent.name);
gives me a layer within the iFrame.
//
That is actually the name of my iFrame. I have tried the following code, but it didn't work either.
x = window.parent.parent.getEl
alert(x.innerHTML);
ASKER
x = window.parent.parent.docum ent.getEle mentById(' Results');
Gives - Access is denied error
Does that have anything to do with the embedded frame being on a different web server than the parent?
Gives - Access is denied error
Does that have anything to do with the embedded frame being on a different web server than the parent?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is what I was afraid of. It looks like I may have to transfer my pages to the other web server to get it to work that way. That does make sense from a security standpoint. Thanks for the help!
Jayh99,
It seems like my comment above answered your question. The answer was you can't do it because the pages are on a different server. I'm a little surprised you said you didn't get an answer when your last comment seems to acknowledge it. I did provide information in that comment on why it wouldn't work but let me know if you still have a question. Let me know your thoughts on this.
bol
It seems like my comment above answered your question. The answer was you can't do it because the pages are on a different server. I'm a little surprised you said you didn't get an answer when your last comment seems to acknowledge it. I did provide information in that comment on why it wouldn't work but let me know if you still have a question. Let me know your thoughts on this.
bol
@Netminder - How do we create links to a specific comment using just the new site (sans QP)? Just curious if you have a tip. :)
bol
bol
@Netminder - Thanks!
bol
bol
{
if (document.getElementById)
{
x = parent.document.getElement
x.innerHTML = '';
x.innerHTML = text;
}
else if (document.all)
{
x = parent.document.all[id];
x.innerHTML = text;
}
else if (document.layers)
{
x = parent.document.layers[id]
text2 = '<P CLASS="testclass">' + text + '</P>';
x.document.open();
x.document.write(text2);
x.document.close();
}
}