How to check if i am using local or remote access to my HA

Hi everyone!

Recently i start to work with a new Dashboard:

My plan is to any click in every one of the 6 tiles in the section named “Virtual Machines” will open the vm url in a new browser tab.

And all VMs in this section has his particular cloudflare url.

So, when i am accessing from outside the url is (by example):
https://mycloudflaredomain.com/phpMyAdmin/

But, when i am acessing from inside of my network the url must be:
https://192.x.x.x/phpMyAdmin/

And there is the catch:
1st. When the click occours i need to know if i am in the local or in the remote network to open the correct url (the cloudflare one or the local ip one).

2nd. How can i open a url from a script? (i am thinking in run a script when tap_action takes place, to arbiter if i redirect to local or remote url)

Any help? Thanks in advance!!