-1

I am getting JS input code from a textarea and appending this into a Iframe body. then if any wrong syntax is input by user browser shows console errors. I want to show custom errors and stop console to show any errors. How can I do that in chrome or any other browsers ??

this is code

<textarea id="js" placeholder="Write JS / Jquery code here"></textarea>

<script>
    jsContent='<script>' + $('#js').val() + '</script>';
    $('body',targetIframe).append(jsContent); 
</script>

output will be like this

<iframe id="preview" src="">
   <!DOCTYPE html>
                <html>
                <head>
                    <title></title>
                    <meta charset="utf-8">
                </head>
                <body>
                    <scrip>textarea input goes here</script>
                </body>
                </html>

            </iframe>
  • Your javascript have to be inside [` – Alexander Nov 11 '17 at 18:20
  • i have concatenated '; – DINESH Kumar SISODIYA Nov 11 '17 at 18:24
  • 1
    Possible duplicate of [How do you send console messages and errors to alert?](https://stackoverflow.com/questions/20253652/how-do-you-send-console-messages-and-errors-to-alert) – Daniel Beck Nov 11 '17 at 18:50
  • I tried that way also, but did not work.. – DINESH Kumar SISODIYA Nov 11 '17 at 18:56
  • A better way is to create a log file if you like to rather than showing everything on alert you can use one good framework log4js if you like you can categorize which errors, warnings, exceptions to log and which to throw on the console or prompt. log4js – Muhammad Omer Aslam Nov 11 '17 at 19:36
  • @DINESHSISODIYA , your JavaScript, *that started from `jsContent=` and finished by `.append(jsContent);`*, have to be inside script tag. – Alexander Nov 12 '17 at 03:52

1 Answers1

0

Does it work like that?

<textarea id="js" placeholder="Write JS / Jquery code here"></textarea>
<script>
$('body',targetIframe).append($('#js').val());
</script>
Radu
  • 995
  • 12
  • 23