0

My code is somewhat like this:

<?php

if($_REQUEST['post'])
{
    $title=$_REQUEST['title'];
    $body=$_REQUEST['body'];
    echo $title.$body;
}
?>

<script type="text/javascript" src="texteditor.js">
</script>

<form action="" method="post">
       Title: <input type="text" name="title"/><br>

       <a id="bold" class="font-bold"> B </a> 
       <a id="italic" class="italic"> I </a>

       Post: <iframe id="textEditor" name="body"></iframe>

       <input type="submit" name="post" value="Post" />
</form>

The texteditor.js file code is:

$(document).ready(function(){
document.getElementById('textEditor').contentWindow.document.designMode="on";
document.getElementById('textEditor').contentWindow.document.close();
$("#bold").click(function(){
    if($(this).hasClass("selected")){
        $(this).removeClass("selected");
    }
    else{
        $(this).addClass("selected");
    }
    boldIt();
});

$("#italic").click(function(){
    if($(this).hasClass("selected")){
        $(this).removeClass("selected");
    }
    else{
        $(this).addClass("selected");
    }
    ItalicIt();
});


});

function boldIt(){
    var edit = document.getElementById("textEditor").contentWindow;
    edit.focus();
    edit.document.execCommand("bold", false, "");
    edit.focus();
}

function ItalicIt(){  
    var edit = document.getElementById("textEditor").contentWindow;
    edit.focus();
    edit.document.execCommand("italic", false, "");
    edit.focus();
}

function post(){
    var iframe = document.getElementById("body").contentWindow;
}

Actually I want to fetch data from this text editor (which is created using iframe and javascript) and store it in some other place. I'm not able to fetch the content that is entered in the editor (i.e. iframe).

Please help me out in this.

2
  • 2
    possible duplicate of how to get the content of iframe in a php variable? Commented Jun 17, 2012 at 21:37
  • that question was closed. since i'm new to this. i don't know how to reopen after editing the question. so, i posted a new one. Commented Jun 17, 2012 at 21:59

1 Answer 1

1

You can't do that because it is not allowed.

Javascript is not allowed access to other frames/iframes, as it would result in a security breach.

Try to implement your editor inline in a <div></div> instead of iframe

Sign up to request clarification or add additional context in comments.

5 Comments

i tried <div> instead of <iframe> but the editor is not working now... do i require to make some changes in javascript file also??
You have to implement your editor in your page directly. Simply linking it in won't help you much.
then how would i store the content that will be edited? i need to store it.
@Story Teller: sorry but i couldn't get you. what are you trying to ask me?
can you quote some code sample in Html5 by which i can get how to do what i want...??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.