SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting element in iFrame

    Take a look at the sample code to insert an element in iFrame:

    Code HTML4Strict:
    <html>
    	<head>
    		<title>Sample iFrame</title>
    	</head>
    	<body>
    		<script language="javascript">
    			var o = document.createElement( "iframe" );
    			o.id = 'A';
    			document.body.appendChild( o );
    			p = document.createElement('p');
    			p.innerHTML = "Test";
    			alert( document.getElementById( 'A' ).contentWindow.document.body );
    			document.getElementById( 'A' ).contentWindow.document.body.appendChild( p );
    		</script>
    	</body>
    </html>

    This is working in Firefox. But this is not working in Internet Explorer (Getting null in the alert).

    I got the same problem when working with FCK editor. Even the InsertElement() function is also returning error in Internet Explorer, working in Firefox.

    In case of FCK editor I tried following cases:

    Code JavaScript:
    p = document.createElement('p');
    p.innerHTML = "Test";
    FCKeditorAPI.GetInstance('FCKeditor1').InsertElement( p );


    Code JavaScript:
    p = document.createElement('p');
    p.innerHTML = "Test";
    var objEditorDocument = document.getElementById('FCKeditor1___Frame').contentWindow.document.getElementsByTagName('iframe')[0].contentWindow.document.body;
    objEditorDocument.appendChild(p );


    Code JavaScript:
    p = document.createElement('p');
    p.innerHTML = "Test";
    FCKeditorAPI.GetInstance('FCKeditor1').EditorDocument.body.appendChild( p );

    None of the techniques worked for me.

  2. #2
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got solution.

    If you want to add an element to a iframe, then we should create element of that iframe's document.


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
  •