# Detect if code is being run in editor or embedded

**URL:** <https://discourse.processing.org/t/detect-if-code-is-being-run-in-editor-or-embedded/21259>\
**Category:** Coding Questions\
**Created:** [May 24, 2020, 6:10pm UTC](https://discourse.processing.org/t/detect-if-code-is-being-run-in-editor-or-embedded/21259 "2020-05-24T18:10:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![STEMcoding](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@STEMcoding](https://discourse.processing.org/u/STEMcoding)\
**Post date:** [May 24, 2020, 6:10pm UTC](https://discourse.processing.org/t/detect-if-code-is-being-run-in-editor-or-embedded/21259/1 "2020-05-24T18:10:25Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 24, 2020, 6:39pm UTC](https://discourse.processing.org/t/detect-if-code-is-being-run-in-editor-or-embedded/21259/2 "2020-05-24T18:39:49Z")

</div>

> [@STEMcoding](#):
>
> … to detect whether the code is being run in the [http://editor.p5js.org](http://editor.p5js.org) environment…

You may try out _location_: 💡

> **[Window: location property - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/location)**
>
> The Window.location read-only property returns a Location object with information about the current location of the document.

---

<div class="post-metadata">

**Author:** ![STEMcoding](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@STEMcoding](https://discourse.processing.org/u/STEMcoding)\
**Post date:** [May 24, 2020, 6:46pm UTC](https://discourse.processing.org/t/detect-if-code-is-being-run-in-editor-or-embedded/21259/3 "2020-05-24T18:46:48Z")

</div>

That does seem to work!

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

```

Thanks a bunch!
