Results 1 to 8 of 8

Thread: iframe contentDocument

  1. #1
    Join Date
    Feb 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question iframe contentDocument

    hi i have a problem like this


    <iframe id="frame" src="contents.htm"></iframe>

    in contents.htm I have an <div id="area">Our Content</div> and i want to reach div's inner html to change Our Content

    in main page i write this code but it dosnt work

    <script>
    var x=null;
    x=document.getElementById("frame");
    alert(x.contentDocument.getElementById("area").innerHTML);
    //i cant reach divs content please help
    </script>

  2. #2
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Hmm. Can we see more of your page? I tried this:
    Code:
    <script type="text/javascript">
    function hidediv(){
    document.getElementById("frame").contentDocument.getElementById("area").style.display = "none";
    }
    </script>
    and it worked for me. Also, what does it alert? Null, Object, Undefined?
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If you access the iframe as a part of the window.frames collection, like - say it was the first iframe on the page:

    Code:
    alert(window.frames[0].document.getElementById('area').innerHTML);
    It's much simpler. When you access the iframe as an element on the page, the object that represents the content document actually varies from browser to browser.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Feb 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Now i can rich iframe content with this code

    var oIframe = document.getElementById('frame1');
    var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
    if (oDoc.document) oDoc = oDoc.document;
    alert(oDoc.getElementById('frame1').id);//Show id in message box


    but i cant use this code

    oDoc.getElementById('area').focus ;

    i cant focus so i cant change my text editor content

    Note: i am making sitebuilder for university and user can edit his or her content and when he wants to prewiev i want to call iframe it looks like so simple but i cant please help if anyone has a simple editor not like FCKEditor ...
    Thanks..
    Last edited by sir_yunus; 02-16-2008 at 10:41 AM.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Top page:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function intoIframe(fr, el_id, txt){
    window.frames[fr].document.getElementById(el_id).innerHTML=txt;
    }
    </script>
    </head>
    <body>
    <iframe src="ed.htm" width="300" height="300" scrolling="auto" frameborder="1"></iframe><br>
    <input type="button" onclick="intoIframe(0, 'ed1', 'Hello World');" value="Test">
    </body>
    </html>
    ed.htm:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    <div id="ed1">
    
    </div>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Feb 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yes this code is well but ihave an another problem can you give your email me
    mine is byron34master@gmail.com if you give or mail to me i can send my project and you will se my problem and may be you will help me

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That other problem wouldn't happen to be that you are trying to populate a textarea rather than a div tag? If so, you need to access its value, not its innerHTML:

    Code:
    window.frames[fr].document.getElementById(el_id).value=txt;
    My email is available if you click on my user name wherever it is a link on this forum. That will take you to my View Profile where there is information for contacting me. I would rather not actually publish my email address here for obvious reasons.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Feb 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    var frame1=document.getElementById('frame1');
    var icerik=frame1.document.getElementById('area').id;

    i write this code but i cant reach again i must use div not textarea because i am making sitebuilder

    plz help

Bookmarks

Posting Permissions

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