# How can I build a "back" button?

**URL:** <https://community.noloco.io/t/how-can-i-build-a-back-button/1764>\
**Category:** Ask for Help\
**Created:** [February 28, 2025, 7:58pm UTC](https://community.noloco.io/t/how-can-i-build-a-back-button/1764 "2025-02-28T19:58:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_4N](https://dub1.discourse-cdn.com/flex005/user_avatar/community.noloco.io/_4n/32/1472_2.png) [@\_4N](https://community.noloco.io/u/_4N)\
**Post date:** [February 28, 2025, 7:58pm UTC](https://community.noloco.io/t/how-can-i-build-a-back-button/1764/1 "2025-02-28T19:58:11Z")

</div>

I really, really, **really** need a simple Button that does `onclick="window.history.back()"`

Is there any way, trick or workaround to archive this?

If not, could you _please_ just add the option “Navigate to → Previous Page” to the Action “Navigate to” @noloco team?

I honestly think noloco is great but the fact that i cannot build a simple “back” button feels slightly ridiculous.

---

<div class="post-metadata">

**Author:** ![carlos](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@carlos](https://community.noloco.io/u/carlos)\
**Post date:** [February 28, 2025, 9:18pm UTC](https://community.noloco.io/t/how-can-i-build-a-back-button/1764/2 "2025-02-28T21:18:56Z")

</div>

Hi @_4N, you can achieve something similar with a navigation button and set it to go to whatever the previous page is. Have you tried using the _ **Navigate to** _ action?

---

<div class="post-metadata">

**Author:** ![\_4N](https://dub1.discourse-cdn.com/flex005/user_avatar/community.noloco.io/_4n/32/1472_2.png) [@\_4N](https://community.noloco.io/u/_4N)\
**Post date:** [February 28, 2025, 9:37pm UTC](https://community.noloco.io/t/how-can-i-build-a-back-button/1764/3 "2025-02-28T21:37:48Z")

</div>

Yea but this does not work for records because you can get there from different locations.

Breadcrumps are not an option because they display a link to the underlaying database which only lead to confusion in the past so we abandoned them all together for the user group in question.

Buttons on top of the page make for really nice navigational elements, especially for the mobile view. But not being able to have a dynamic “back” button cripples this approach too 😕

Shoudn’t it be fairly easy to just allow a “dynamically go to previous page” option for the “navigate to…” action?  
It would make a huge difference for building a better user experience.

---

<div class="post-metadata">

**Author:** ![darragh](https://dub1.discourse-cdn.com/flex005/user_avatar/community.noloco.io/darragh/32/12_2.png) [@darragh](https://community.noloco.io/u/darragh)\
**Post date:** [March 3, 2025, 7:04am UTC](https://community.noloco.io/t/how-can-i-build-a-back-button/1764/4 "2025-03-03T07:04:28Z")

</div>

@_4N - you can probably wire this up with simple Javascript, by targeting the button by it’s action-button ID.

If that’s what you’re looking to do, that is probably the best suggestion

---

<div class="post-metadata">

**Author:** ![\_4N](https://dub1.discourse-cdn.com/flex005/user_avatar/community.noloco.io/_4n/32/1472_2.png) [@\_4N](https://community.noloco.io/u/_4N)\
**Post date:** [March 11, 2025, 11:25am UTC](https://community.noloco.io/t/how-can-i-build-a-back-button/1764/5 "2025-03-11T11:25:21Z")

</div>

I finally came around trying this today and it seems to work.  
Admittedly I used chat GPT to write the script so I quickly wanted to post it here and ask if an actual developer sees any issues with it.

```auto
<script>
  function attachClickHandler() {
    // List of button classes or IDs you want to target
    const buttonSelectors = [
      '.action-button-z7eyhHFdB', // First button selector
      '.action-button-C-hkxyARw' // Second button selector (your new button)
    ];

    buttonSelectors.forEach(selector => {
      const button = document.querySelector(selector);
      if (button && !button.hasAttribute("data-click-handler")) {
        button.setAttribute("data-click-handler", "true"); // Prevents duplicate handlers
        button.onclick = function() {
          console.log("Button clicked!");
          window.history.back();
        };
      }
    });
  }

  // Run every second to ensure the buttons keep working
  setInterval(attachClickHandler, 1000);
</script>

```

It woudn’t work at first, after some troubleshooting it seemed that noloco was dynamically changing things in the background which caused the script to not function.

I am a bit worried the skript will cause performance issues, if that would be the case, a headsup would be appreciated.
