How can I implement a Javascript/HTML Playground with Javascript?
NickName:Seb Ask DateTime:2011-12-12T04:51:42

How can I implement a Javascript/HTML Playground with Javascript?

I would like to implement a simple Javascript Playground like jsFiddle and was wondering on the best way to achieve this. From the way jsfiddle works, it creates an iframe with the submitted HTML/Javascript code. The source of the iframe comes from a dynamically created page from the jsfiddle server.

I was wondering if it would be possible to do this with client side javascript code only. I have tried this but does not work (custom code is not executed and do not know if jquery is loaded in the iframe):

$iframe = $(document.createElement("iframe"))

$html = $iframe.contents().find("html")

//HTML code
$html.children("body").append($(htmlcode))

//Javascript code (first jquery and then custom code)
$script = $(document.createElement("script"))
$script.attr("src","jquery.js")
$html.children("head").append($script)

$script = $(document.createElement("script"))
$script.html(javascriptcode)
$html.children("head").append($script)

$iframe.appendTo($("body"));

Copyright Notice:Content Author:「Seb」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/8467360/how-can-i-implement-a-javascript-html-playground-with-javascript

Answers
Derek 朕會功夫 2011-12-11T21:34:19

You don't have to be that complex.\nJust open a new window (or an iframe) and put your HTML inside it.\n\nDemo: http://jsfiddle.net/DerekL/uSrU6/4 (UPDATED)",


More about “How can I implement a Javascript/HTML Playground with Javascript?” related questions

How can I implement a Javascript/HTML Playground with Javascript?

I would like to implement a simple Javascript Playground like jsFiddle and was wondering on the best way to achieve this. From the way jsfiddle works, it creates an iframe with the submitted HTML/

Show Detail

How to implement this JavaScript in HTML

This is a JavaScript showing time hour, minute and seconds now seconds are ticking minutes change it's not static i have problem.How to implement it in HTML page ? <script type="text/javasc...

Show Detail

How can I implement resizing in Javascript?

I know that jQuery and similar Javascript frameworks offer resize functionality, but I want to understand how it's implemented (if only to learn more about Javascript). I can think of a few ways it

Show Detail

How to implement a list container in html / Javascript?

Hi i am new to Html and javascript and want some suggestion on how to implement a list container in Html, like when the user selects one of the files using browse b button then those file should ap...

Show Detail

How can I implement html code in javascript

I want to run the HTML code when the condition in javascript is OK. this is the javascript code. <script type="text/javascript"> $(document).ready(function () { if(window.location...

Show Detail

How to implement intelxdk using JavaScript in HTML?

How & where should I implement this JavaScript method below in my index.html file? I am using this code to access the native code of android in intelxdk smsplugin.startReception(successCallback(

Show Detail

How can I create a menu in HTML without using Javascript?

Since many years a GUI-standard are the menu-bars of applications with menus popping up, if you click or hover an entry in the menu-bar. Some websites implement this feature too, but they are using

Show Detail

How to implement html uncode function with JavaScript

html.replace(/</g, "<").replace(/>/g, ">" is there any JavaScript function can implement this function, seems like unescape function or escape function, which can convert displ...

Show Detail

How can I implement partial classes in JavaScript?

How can I implement partial classes in JavaScript? For example, I have a class like this: function MyClass(){ this.myName = "I am native member"; }; myObj = new MyClass(); console.log(myObj....

Show Detail

How can I implement an array of functions in JavaScript?

I am still new to JavaScript. I need to code a 20 x 20 matrix pair of functions. All my functions take in a number in and return a number (i.e, same signature). For example, Myfunctions[1][2] should

Show Detail