Logic Machine Forum
Local or Remote connection availability - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Local or Remote connection availability (/showthread.php?tid=582)



Local or Remote connection availability - buuuudzik - 28.01.2017

I am trying to prepare such javascript function which would check if client can connect locally or remotely. I want use this function e.g. for changing image src from local to remote:port.

I thinked that this will be easy but there is a problem with no CORS headline.

Maybe someone has some solution?

At this moment I've prepared such solution for this task:

1. Adding 2 images with classes: '.local'(from LM local address) and '.remote'(from LM remote address)

2. Adding this function to js.
Code:
var local = $('.local > img')[0].naturalHeight > 0;
var remote = $('.remote > img')[0].naturalHeight > 0;
console.log(local, remote)
if (remote){ if(local){
alert('Local');
} else if(!local){
alert('Remote');
}
};
If someone has some better solution please shareWink


RE: Local or Remote connection availability - admin - 30.01.2017

If you are accessing via port forwarding then you can use window.location.host to check whether client is requesting locally or remotely.


RE: Local or Remote connection availability - buuuudzik - 30.01.2017

I've tried this but this tells only which shortcut user selects, no if client is lin local network or if it connects via internet. The best way will be by ping LM local address but there is some problem with using such function in js with security(cems problem (?)). The easiest working way is to add some img with local address via remote link.