I need to access an element on main page from iframe. I open a page in an iframe and in that is code to change colors of divs and what not but I cannot seem to get to them.
Thanks in advance,
Michael
Printable View
I need to access an element on main page from iframe. I open a page in an iframe and in that is code to change colors of divs and what not but I cannot seem to get to them.
Thanks in advance,
Michael
I think it may be in this line and not the iframe at all:
I get a "object dosent support property or method" on this lineCode:document.getElementByID('find').style.background='yellow';
Michael
I think I understand what you are doing. You have a main page in which the iframe is 'embedded' and you want dynamically change a divs properties using a script from the page displayed in the iframe?
In this case you need use window.parent which will point to the parent window. Try this...
Code:window.parent.find.style.background='yellow';
This finds the element but still has the error mentioned above:
I get the error:Code:window.parent.getElementById('find').style.background='yellow';
I should probably start a new thread cos it is a new problem but oh well :)Quote:
Object doesn't support this property or method
Any ideas?
Michael
try taking out the getElementById('')
Without that it won't find the element... I forgot to add details (I get interupted alot here and forget what I am doing). The element is a div that I am using as a button. I want to change the color of it from the Iframe when the user clicks on it.
Michael
It's strange because I've just tested window.parent.button1.style.backgroundColor='yellow'; and it seems to work.
What are you calling the script from? an object inside the iframe?
scroll to bottom of this post first
here is the viewsource of the iframe (both attempts)
AndCode:<HTML>
<HEAD>
<TITLE> </TITLE>
</HEAD>
<BODY>
<script language="javascript">
window.parent.ElementById('find').style.background='yellow';
</script>
</BODY>
</HTML>
With the first (getelement) I get the obect dosent support but with the second (w/o get element) I get:Code:<HTML>
<HEAD>
<TITLE> </TITLE>
</HEAD>
<BODY>
<script language="javascript">
window.parent.find.style.background='yellow';
</script>
</BODY>
</HTML>
here is the ............Quote:
'window.parent.find.style' is null or not an object
Ignore all of that
I appologize. I had changed the name of the "find" and thats why it wasn't finding it.... oops :)
Thanks
Michael
No problem, it was just a simple mistake. ;)
I don't mind that I waste my time due to my mistakes but hate wasting others.
But... why dosen't getElementById work I thought that was the correct way to call elements?
Michael
That's ok, I'm just avoiding working ;)
getElementById('') is part of the document object which is part of window. Its the same as using window.document.getElementById(''). When you use window.parent or window.opener you're not using the document object so I guess the syntax is different.
This is only what I assume from what I've read around the web, someone else maybe able to give you some further information.