# \[solved\] worldmap - button - redirect using window.location.foo

**URL:** <https://discourse.nodered.org/t/solved-worldmap-button-redirect-using-window-location-foo/48903>\
**Category:** General\
**Created:** [26 July 2021 04:58 UTC](https://discourse.nodered.org/t/solved-worldmap-button-redirect-using-window-location-foo/48903 "2021-07-26T04:58:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [26 July 2021 04:58 UTC](https://discourse.nodered.org/t/solved-worldmap-button-redirect-using-window-location-foo/48903/1 "2021-07-26T04:58:58Z")

</div>

Wondering if there is a way to send a

```auto
window.location.replace

```

or a

```auto
window.location.href

```

using a button in worldmap

I can create buttons in the map and register the click event to the `worldmap in` node and receive the `action` but now what.... care to point me in the right direction ?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 July 2021 07:50 UTC](https://discourse.nodered.org/t/solved-worldmap-button-redirect-using-window-location-foo/48903/2 "2021-07-26T07:50:20Z")

</div>

Why not just add the action to the button itself ? No need to send to the backend ?

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [26 July 2021 14:14 UTC](https://discourse.nodered.org/t/solved-worldmap-button-redirect-using-window-location-foo/48903/3 "2021-07-26T14:14:08Z")

</div>

> Why not just add the action to the button itself ? No need to send to the backend ?

Oh I thought about doing that using `onclick` and doing that but I have other logic outside of the map I want to forward the user to a url.

This all comes back to the camera system I created using worldmap. That way I can trigger the action as well.  
I just wanted to make sure I was not missing a easy solution before diggin in the innards.  
If its not possible I'll pull up your github repo and start reading and maybe code it in.

I figure it could work like i did with the dashboard [https://discourse.nodered.org/t/howto-dashboard-button-link-to-url-with-no-ui-template-for-only-the-current-user-on-the-page/33210](https://discourse.nodered.org/t/howto-dashboard-button-link-to-url-with-no-ui-template-for-only-the-current-user-on-the-page/33210)

The camera map

 ![Screenshot from 2021-07-26 10-10-07](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/7/d79241d03057e5d978006b51ec0229837390664c.jpeg)

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [26 July 2021 16:10 UTC](https://discourse.nodered.org/t/solved-worldmap-button-redirect-using-window-location-foo/48903/4 "2021-07-26T16:10:29Z")

</div>

> [@meeki007](#):
>
> button

Ohhhhhh......... just found the code for the 3d view. Looks like I can build on this to do what I want.

```auto
document.addEventListener ("keydown", function (ev) {
    // Set Ctl-Alt-3 to switch to 3d view
    if (ev.ctrlKey && ev.altKey && ev.code === "Digit3") {
        ws.close();
        window.location.href = "index3d.html";
    }
    // Set Esc key to close all open popups
    if (ev.keyCode === 27) {
        map.eachLayer(function (layer) {
            layer.closePopup();
        });
    }
});

```

now I just need to tie it into the button or .........better create a new **command** object for Controlling the map. hmmmm what to call it?

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [26 July 2021 18:55 UTC](https://discourse.nodered.org/t/solved-worldmap-button-redirect-using-window-location-foo/48903/5 "2021-07-26T18:55:59Z")

</div>

@dceejay well that was not too hard

```auto
if (cmd.hasOwnProperty("redirect")) {
      if (typeof cmd.redirect === "string") {
          ws.close();
          window.location.href = cmd.redirect;
      }
    }

```

trigger it using

```auto
msg.payload = {"command":{ "redirect": "https://google.com" }};

```

Tested working as triggered or with a button tied to a `msg._sessionid` with multiple sessions open to make sure it did not redirect all sessions 🙂

I'd be happy to write up the documentation and submit a PR if you want the addition like i did for the **weblink** \*array of objects addition I did.

Thanks for working with me m8

PS: or no documentation and just PR to sneak it in so every time I update worldmap I dont have to ftp in and edit the worldmap.js file 😛

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [26 July 2021 20:28 UTC](https://discourse.nodered.org/t/solved-worldmap-button-redirect-using-window-location-foo/48903/6 "2021-07-26T20:28:35Z")

</div>

Got bored, Pull request submitted.

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [26 July 2021 20:57 UTC](https://discourse.nodered.org/t/solved-worldmap-button-redirect-using-window-location-foo/48903/7 "2021-07-26T20:57:53Z")

</div>

Also the main benefit for all of this is to keep local network users from loading the map from a saved url. I need them to login because ive had some bad actors..... Who would have thought that a user would just keep loading cameras and leaving them open 😑 boggin down the camera server to all hell.

Fake names used:  
So Jenny needs access to the cameras to check on theft. But then one day she decides she wants to have the parking lot camera streaming in her borwser so she can watch in on her new car. Well Jeff from accounting see the camera on her screen and asks, "hey how you get that? "

Well 2 weeks later I have a server bogged down with about 20 people all with cameras streaming all sorts of things. I ask Paul from the warehouse " why do you need to stream the cafeteria? and he says "don't want no one messing with my lunch."

Oh the hell that is my life.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 September 2021 20:58 UTC](https://discourse.nodered.org/t/solved-worldmap-button-redirect-using-window-location-foo/48903/8 "2021-09-24T20:58:34Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
