|
-
Sep 4th, 2002, 01:42 PM
#1
Thread Starter
Frenzied Member
(javascript) Accessing element on main page from iframe.
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'm off to GalahTech, hope to see you there.
If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.
-
Sep 4th, 2002, 01:47 PM
#2
Thread Starter
Frenzied Member
I think it may be in this line and not the iframe at all:
Code:
document.getElementByID('find').style.background='yellow';
I get a "object dosent support property or method" on this line
Michael
I'm off to GalahTech, hope to see you there.
If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.
-
Sep 5th, 2002, 03:07 AM
#3
Fanatic Member
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';
-
Sep 5th, 2002, 09:09 AM
#4
Thread Starter
Frenzied Member
This finds the element but still has the error mentioned above:
Code:
window.parent.getElementById('find').style.background='yellow';
I get the error:
Object doesn't support this property or method
I should probably start a new thread cos it is a new problem but oh well 
Any ideas?
Michael
I'm off to GalahTech, hope to see you there.
If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.
-
Sep 5th, 2002, 09:14 AM
#5
Fanatic Member
try taking out the getElementById('')
-
Sep 5th, 2002, 09:20 AM
#6
Thread Starter
Frenzied Member
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
I'm off to GalahTech, hope to see you there.
If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.
-
Sep 5th, 2002, 09:42 AM
#7
Fanatic Member
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?
-
Sep 5th, 2002, 09:51 AM
#8
Thread Starter
Frenzied Member
scroll to bottom of this post first
here is the viewsource of the iframe (both attempts)
Code:
<HTML>
<HEAD>
<TITLE> </TITLE>
</HEAD>
<BODY>
<script language="javascript">
window.parent.ElementById('find').style.background='yellow';
</script>
</BODY>
</HTML>
And
Code:
<HTML>
<HEAD>
<TITLE> </TITLE>
</HEAD>
<BODY>
<script language="javascript">
window.parent.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:
'window.parent.find.style' is null or not an object
here is the ............
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
I'm off to GalahTech, hope to see you there.
If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.
-
Sep 5th, 2002, 09:57 AM
#9
Fanatic Member
No problem, it was just a simple mistake.
-
Sep 5th, 2002, 10:01 AM
#10
Thread Starter
Frenzied Member
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
I'm off to GalahTech, hope to see you there.
If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.
-
Sep 5th, 2002, 10:12 AM
#11
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|