Detect if code is being run in editor or embedded

I would like to be able to add something to my p5.js code to be able to detect whether the code is being run in the http://editor.p5js.org environment or if it is being run embedded in a website.

If in the editor then I would write a message to the user with print() so they can see it in the bottom left.

If the code is embedded then I would want to write a message using the dom and createP()

The problem is that I need to be able to detect whether the code is being run in the editor or being run embedded. Any advice?

Note: It is basically impossible to see the web console with iPads so writing messages to the dom is a clever way to see error messages.

1 Like

You may try out location: :bulb:

2 Likes

That does seem to work!

if( location.hostname === "") {
    print("in the editor");
} else {
   print("must be embedded");
}

Thanks a bunch!

1 Like