Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Writing to an iframe in a framepage in Firefox

    I have seen plenty of online sources tell of how to write to an iframe, that it is a property of "window". But the problem is, the iframe in question is in a frame itself. How do I refer to such an iframe?

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by Joat View Post
    I have seen plenty of online sources tell of how to write to an iframe, that it is a property of "window". But the problem is, the iframe in question is in a frame itself. How do I refer to such an iframe?
    Refer the iframe from where? From the parent frame? From the general parent? From another frame/iframe? Describe the structure of your page, please.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    A script in the top-left frame writing content to an iframe in the same frame. The script may be called from another frame, but the script itself is in the same frame.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    So the code is in the same frame with the iframe. Now give your iframe an id, say id="myiframe". Now, the iframe, as a Global Object (window), is to be referred as:
    Code:
    var ifr=document.getElementById('myiframe').contentWindow
    Well, there were some problems around contentWindow method (which is not quite DOM standard, even it is recognized now by all the modern browsers). If you feel the need to be pedantic, you may access the document of the iframe like:
    Code:
    var x=document.getElementById('myiframe');
    var ifr_document;
    if(x.contentWindow){
    ifr_document=x.contentWindow.document;
    }
    else{
    ifr_document=x.contentDocument;
    }
    ----

    IMPORTANT note. Javascript reference for frames or iframes works only if both (the parent document and the iframe/frame document) belong to the same domain. Cross-domain javascript relationship is not possible, due to obvious security reasons.
    Last edited by Kor; 05-31-2009 at 06:20 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    Joat (06-01-2009)


  •  

    Posting Permissions

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