Saturday 8 April 2017

google caja like mechanism for offline application

I want to allow user to write their own javascript which will be run in my application like caja.

Below is the caja application to print hello in my application

<html>
  <head>
    <title>Caja host page</title>
    <script type="text/javascript"
            src="http://caja.appspot.com/caja.js">
    </script>
  </head>

  <body>
    <h1>Caja host page</h1>
    <div id="guest"></div>
    <script type="text/javascript">
      caja.initialize({
        cajaServer: 'https://caja.appspot.com/',
        debug: true
      });
      caja.load(document.getElementById('guest'), undefined, function(frame) {
        // This URL is actually ignored and yet the caja API requires
        // a URL to be passed and for it not to be null or empty (!)
        var url = 'http://example.com/example.js';

        // A string that will be run in the context of the virtual document
        // in the div with id "guest" identified above.
        var javascriptString = 'document.write("hello")';

        // Execute the code.
        frame.code(url, 'application/javascript', javascriptString).api({}).run();
      });
    </script>
  </body>
</html>

To run caja use required must have internet connectivity but as per my requirement I have to run this code offline.

Is there any way, mechanism or technology to run user script in my application ?



via user3812269

No comments:

Post a Comment