0

Im trying to make a html/css/javascript online editor so I create a textarea to write the code and Iframe to display it so this is the html :

 <textarea id="code"></textarea>

 <iframe id="output"></iframe>

 <button id="submit-b">submit</button>

and this is the jquery code :

$("#submit-b").click(function(){
   code = $("#code").val();
   $('#output').contents().find('body').html(code);
});

it works to edit html and Css but not JavaScript, how can I do this?

2
  • Why not use an existing editor like TinyMCE or something like JSFiddle, depending on your needs? Commented Jan 26, 2014 at 14:15
  • I want this editor not for me I want it as Graduation Project to my University so I must make it , I have 3 days Commented Jan 26, 2014 at 14:22

3 Answers 3

1

It works for me: JSFiddle example. Enter something like this in the textarea:

<script>alert('Boo!');</script>

And you will be whown a Javascript alert.

That said, why not use an existing editor like TinyMCE or something like JSFiddle, depending on your needs?

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

2 Comments

no it didn't work with me in your JSFiddle example try to input a full html page like : <!DOCTYPE html> <html> <body> <h1>My First JavaScript</h1> <p>Click the button to display the date.</p> <p id="demo"></p> <button type="button" onclick="myFunction()">Try it</button> <script> function myFunction() { document.getElementById("demo").innerHTML = Date(); } </script> </body> </html> this will not work
0

Why you don't use code mirror instead?

http://codemirror.net/

Here is sample on how this framework does it:

http://codemirror.net/mode/htmlembedded/index.html

1 Comment

I want this editor not for me I want it as Graduation Project to my University so I must make it I have 3 days left thank you
0

the solution is to use a pure javascript code which is it :

function update() 
{
var w = document.getElementById("code").value;
document.getElementById('output').contentWindow.document.write(w);
}

becouse jquery code append the textarea value without <html> and <body> tags

Comments

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.