writing html in a div affects whole document
Hi guys,
I have a function that takes a user html input and writes into a div.
The html is written as a whole other html document.
The user will write the "<html>" , "<styles>, and <script> tags and the whole content
in a and textarea, it then get's outputted as html in a div.
Everything works fine, but when the user applies a body color style rule the color gets applied not only to the div but also the whole of the page. Also the body background color doesn't seem to work, my guess is that it reading the "body" html in the div as the body of the page.
I'm trying to recreate an html editor.
am I doing it the wrong way? Is there a way around this?
The Html Code:
- <div id="editor">
- <form id="inputForm"method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
- <textarea id="input" name="input" cols="<?php echo $colsIni;?>" rows="<?php echo $rowsIni;?>" onkeyup="Output()"><?php echo $code;?></textarea>
- </form>
- </div>
- <div id="output" class="fakeBrowser">
- </div>
The jQuery code:
- function Output()
- {
- var codeInput = $("#input").val();
- $('#output').html(codeInput);
-
- }
Thanks in advance,
Mike