Results 1 to 11 of 11

Thread: (javascript) Accessing element on main page from iframe.

  1. #1

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057

    (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.

  2. #2

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057
    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.

  3. #3
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    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';
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  4. #4

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057
    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.

  5. #5
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    try taking out the getElementById('')
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  6. #6

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057
    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.

  7. #7
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    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?
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  8. #8

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057
    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.

  9. #9
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    No problem, it was just a simple mistake.
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  10. #10

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057
    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.

  11. #11
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    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.
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width