• Register
  • Log In
  • Home
  • Quick Start
    • Configurator
    • Download YUI 3
  • Documentation
    • User Guides
    • Examples
    • API Docs
    • Environments
    • Tutorials
  • Community
    • Gallery
    • Blog
    • Forums
    • YUI Theater
    • Calendar
  • Contribute
    • YUI on GitHub »
    • File a Ticket
    • View Tickets
    • Dashboard
  • Other Projects
    • Shifter »
    • Yogi »
    • YUI 2
    • YUI Doc »
    • YUI Test
    • YUI Website
    • YUI Compressor »
    • YUI Builder »
    • YUI PHP Loader
    • Grid Builder »
    • Skin Builder »
  • YUI
  • >
  • Community
  • >
  • Gallery

Gallery

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • Yogi Documentation
  • Shifter Documentation
  • Developer Guide
  • Module Setup

Tag Cloud

Context Navigation

    YUI Library is not responsible for bugs or support with this module. It is available as a free service. For support please contact the module owner with the provided links.

    Sandbox (gallery-sandbox) on cdn

    Last Updated: 05/7/10
    + 0 -

    Ryan Grove

    YUI Developer

    See 3 more by this user.

    Created: 05/7/10
    Last CDN Push: 05/12/10
    Build Tag: gallery-2010.05.12-19-08
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.1.1
    Free for use.

    Sandbox simplifies the process of creating isolated iframe sandboxes in which to evaluate JavaScript code for tasks like profiling or unit testing.

    Note that these sandboxes, while isolated enough to be used for testing, are not secure. They should be used only to run trusted code, and are not intended to be used to execute arbitrary untrusted JavaScript.

    • Tags:
    • test
    • profile
    • sandbox
    • rgrove
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Code Sample

    <script src="http://yui.yahooapis.com/3.1.1/build/yui/yui-min.js"></script>
    YUI({
        //Last Gallery Build of this module
        gallery: 'gallery-2010.05.12-19-08'
    }).use('gallery-sandbox', function(Y) {
     
        var sandbox = new Y.Sandbox();
     
        // Listen for the 'ready' event to ensure that the sandbox iframe has
        // been initialized before you try to use it.
        sandbox.on('ready', function () {
            // Run some code in the sandbox.
            sandbox.run('alert("Hello from " + document.title);');
     
            // You can also pass in a function, although it won't retain its
            // execution context when it runs in the sandbox since it will be
            // cast to a string and then evaled.
            sandbox.run(function () { alert("I like pie."); });
     
            // If your code will perform async operations and you'd like to be
            // notified when they've finished, call done() from the sandbox code
            // and pass in a callback to receive the finish notification.
            sandbox.run(function () {
                // Runs in sandbox.
                setTimeout(function () {
                    done();
                }, 1000);
            }, function () {
                // Runs in parent after the sandbox code calls done().
                alert('All done!');
            });
     
            // For easy profiling, run code with profile(). Call done() from the
            // sandbox code to indicate completion. Provide a callback to
            // receive the profile data once it's ready.
            sandbox.profile(function () {
                var i = 5000000;
     
                while (i--) {
                    Math.sqrt(Math.PI);
                }
     
                done();
            }, function (profileData) {
                alert("That took " + profileData.duration + " milliseconds.");
            });
     
            // Pass data between the parent and the sandbox using a shared
            // environment object.
            sandbox.setEnvValue('kittens', 'fuzzy');
            sandbox.run(function () {
                alert('Kittens are ' + sandbox.kittens);
                sandbox.ninjas = 'sneaky';
            });
     
            alert('Ninjas are ' + sandbox.getEnvValue('ninjas'));
     
            // Clean up the sandbox.
            sandbox.destroy();
     
            // See the API docs for even more useful stuff.
        });
     
    });

    Forum Posts

    No forum posts for this module.

    © 2006-2013 Yahoo! Inc. All rights reserved.
    All code on this site is licensed under the BSD License unless stated otherwise.
    About This Site · Security Contact Info