# Is there a way to detect that I'm in Pinegrow with JavaScript?

**URL:** <https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129>\
**Category:** Questions\
**Created:** [January 6, 2022, 10:17am UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129 "2022-01-06T10:17:44Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![fakesamgregory](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/fakesamgregory/32/3903_2.png) [@fakesamgregory](https://forum.pinegrow.com/u/fakesamgregory)\
**Post date:** [January 6, 2022, 10:17am UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/1 "2022-01-06T10:17:44Z")

</div>

I have some JavaScript running that on my page that I DON’T want to run in Pinegrow (even when JS is enabled). How do I do this?

is there a class or element somewhere that exists only within the Pinegrow interface that I can check against? I’m sure there’s a way to find this out myself so a lil help on how to look inside Pinegrow would be fab! Otherwise, for now, I’m checking if the URL is localhost.

e.g.

```auto
if (!document.body.classList.contains('is-pinegrow')) {
  // run the code
}

```

---

<div class="post-metadata">

**Author:** ![TechAkayy](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@TechAkayy](https://forum.pinegrow.com/u/TechAkayy)\
**Post date:** [January 6, 2022, 10:26am UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/2 "2022-01-06T10:26:34Z")

</div>

Hi @fakesamgregory

Assuming your Pinegrow internal server is running at 127.0.0.1 at port 40000, try:

```auto
if(location.host === “127.0.0.1:40000) {
   console.log(“I’m within the Pinegrow matrix”)
}

```

---

<div class="post-metadata">

**Author:** ![fakesamgregory](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/fakesamgregory/32/3903_2.png) [@fakesamgregory](https://forum.pinegrow.com/u/fakesamgregory)\
**Post date:** [January 6, 2022, 10:44am UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/3 "2022-01-06T10:44:26Z")

</div>

Hey @TechAkayy,

Thanks for this. Unfortunately, this does not then run when I preview in the browser. I just want it to not run in the Pinegrow interface.

---

<div class="post-metadata">

**Author:** ![TechAkayy](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@TechAkayy](https://forum.pinegrow.com/u/TechAkayy)\
**Post date:** [January 6, 2022, 10:56am UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/4 "2022-01-06T10:56:03Z")

</div>

May be `location.href`? I think this has some url parameters, and in external browser, I think it doesn’t have url params… haven’t checked this yet at my end!

---

<div class="post-metadata">

**Author:** ![RobM](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@RobM](https://forum.pinegrow.com/u/RobM)\
**Post date:** [January 6, 2022, 11:01am UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/5 "2022-01-06T11:01:41Z")

</div>

@fakesamgregory and @TechAkayy,  
Yeah, @TechAkayy is right. `location.href` in Pinegrow will have have a pgedit URL parameter, while the browser won’t.  
Cheers,  
Bob

---

<div class="post-metadata">

**Author:** ![TechAkayy](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@TechAkayy](https://forum.pinegrow.com/u/TechAkayy)\
**Post date:** [January 6, 2022, 11:02am UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/6 "2022-01-06T11:02:10Z")

</div>

Here you go:

```auto
if(location.search.includes('pgedit'))
  console.log('Editing within pinegrow')

```

---

<div class="post-metadata">

**Author:** ![fakesamgregory](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/fakesamgregory/32/3903_2.png) [@fakesamgregory](https://forum.pinegrow.com/u/fakesamgregory)\
**Post date:** [January 6, 2022, 2:06pm UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/7 "2022-01-06T14:06:41Z")

</div>

Great this works!! Thanks both

---

<div class="post-metadata">

**Author:** ![matjaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/matjaz/32/5_2.png) [@matjaz](https://forum.pinegrow.com/u/matjaz)\
**Post date:** [January 8, 2022, 10:16pm UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/8 "2022-01-08T22:16:15Z")

</div>

Checking for data-pg-id attributes would also work:

```auto
if (!document.body.hasAttribute('data-pg-id') {
  // run the code
}

```

---

<div class="post-metadata">

**Author:** ![fakesamgregory](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/fakesamgregory/32/3903_2.png) [@fakesamgregory](https://forum.pinegrow.com/u/fakesamgregory)\
**Post date:** [May 4, 2022, 10:34am UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/9 "2022-05-04T10:34:37Z")

</div>

> [@matjaz](#):
>
> `data-pg-id`

Extending from this, is there a way to hide/show elements just within Pinegrow from the UI?

Off the head, i’d create a class/attribute `hide-in-pg` and in my CSS…

```css
[data-pg-id] [hide-in-pg] {
  display: none !important;
}

```

---

<div class="post-metadata">

**Author:** ![TechAkayy](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@TechAkayy](https://forum.pinegrow.com/u/TechAkayy)\
**Post date:** [May 4, 2022, 10:42am UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/10 "2022-05-04T10:42:06Z")

</div>

In the tree panel, selecting an element shows the vertical element menu. It has hide/show icon. Is that what you are after?

---

<div class="post-metadata">

**Author:** ![fakesamgregory](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/fakesamgregory/32/3903_2.png) [@fakesamgregory](https://forum.pinegrow.com/u/fakesamgregory)\
**Post date:** [May 4, 2022, 4:13pm UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/11 "2022-05-04T16:13:08Z")

</div>

That’s exactly it. Thank you.

---

<div class="post-metadata">

**Author:** ![fakesamgregory](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/fakesamgregory/32/3903_2.png) [@fakesamgregory](https://forum.pinegrow.com/u/fakesamgregory)\
**Post date:** [March 18, 2023, 8:40am UTC](https://forum.pinegrow.com/t/is-there-a-way-to-detect-that-im-in-pinegrow-with-javascript/6129/12 "2023-03-18T08:40:41Z")

</div>

To bring this back from the dead, Is there any way from the interface to persist @TechAkayy’s suggestion of hiding/showing elements in Pinegrow?

It’d be interesting to see what is more preferred from users using the hide/show icon and whether they’d prefer it if the state persists.

 ![Screenshot 2023-03-18 at 08.39.14](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/d/d1763373d7840b912c79b72cbdb5cef4ef4eaf3e.png)
