Search code examples
javascriptdom-eventsonloadhtml-editor

Why my "PURE JAVASCRIPT BASED" offline file is not supporting "onload" events?


I have a offline "htm" file on my PC which I use to test HTML codes. It is like a HTML editor. It compiles HTML codes. But I have a problem with it. It supports all kinds of CSS and JavaScript and also JavaScript Based Libraries like jQuery but does not support events like- onload, $(document).ready() I don't know why? I have tried many things about it but was able to do nothing.

So see the source code of my editor:

<html>
 <script type="text/javascript">
  function ShowResult()
  {
    my_window = window.open("about:blank", "mywindow1");
    my_window.document.write(x);
    if(my_window.document.title=="")
    {
      my_window.document.title="No title was specified"
    }
  }
 </script>
 <body>
   <textarea style="height:400px;width:750px;overflow:auto;" onblur="x=this.value">
   </textarea><br />
   <button onclick="ShowResult()">see result!</button>
 </body>
</html>

Please tell me what mistake have I done? Why me file is not supporting "onload" events?


Solution

  • You're executing the code within the context of a page that is already loaded.

    Systems like jsfiddle handle this by dynamically generating a page and loading it into an iframe.

    You'd need some sort of server-side scripting to do this. I'd advise installing a local webserver (i.e. Wampserver).