This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

link on scada-vis
#1
Hi,

is there a way to update the external link URL via script?

Thanks

PEPPE

   
Reply
#2
See this: https://forum.logicmachine.net/showthrea...6#pid11806
Reply
#3
(30.10.2024, 15:41)admin Wrote: See this: https://forum.logicmachine.net/showthrea...6#pid11806

$(function() {
  $('.link').off('vclick').on('vclick', function() {
    window.open('http://openrb.com');
  });
});

That's fine, but I need to pass the URL from a key in storage... is it possible?
Reply
#4
Use a virtual object with 250 byte string data type (32/0/1 in this example).
Code:
$(function() {
  if (typeof grp != 'object') {
    return;
  }
  
  var url;

  $('.link').off('vclick').on('vclick', function() {
    window.open(url);
  });

  grp.listen('32/0/1', function(obj) {
    url = obj.value;
  });
});
Reply
#5
(01.11.2024, 07:35)admin Wrote: Use a virtual object with 250 byte string data type (32/0/1 in this example).
Code:
$(function() {
  if (typeof grp != 'object') {
    return;
  }
 
  var url;

  $('.link').off('vclick').on('vclick', function() {
    window.open(url);
  });

  grp.listen('32/0/1', function(obj) {
    url = obj.value;
  });
});


in fact I had already thought of this solution, the problem is that the URL is too long and is truncated to 250 bytes as it contains an authentication token that changes every time:
http://10.0.0.146:8080/dashboard/28a2e20...8So-6_WXUw
Reply
#6
You can create a .lp file that redirects to the specified URL from a storage entry. This way you don't need Custom JS at all. Link URL should be set to /user/redirect.lp.
Code:
<?
require('apps')
url = storage.get('redirect_url')

if url then
  ngx.req.discard_body()
  ngx.redirect(url)
end
Reply
#7
(01.11.2024, 13:03)admin Wrote: You can create a .lp file that redirects to the specified URL from a storage entry. This way you don't need Custom JS at all. Link URL should be set to /user/redirect.lp.
Code:
<?
require('apps')
url = storage.get('redirect_url')

if url then
  ngx.req.discard_body()
  ngx.redirect(url)
end

sorry, but I have no idea about that...  as you can understand, I just need to set a button object or something to click on visu to open a new tab in the browser with the link.

Can you please give me the operating steps to do it?

where I have to put that code and how?

Thanks
Reply
#8
Create redirect.lp file and upload it to user directory via FTP using apps login.
You might still need custom JS to open URL in a new window/tab.
Reply
#9
(01.11.2024, 13:25)admin Wrote: Create redirect.lp file and upload it to user directory via FTP using apps login.
You might still need custom JS to open URL in a new window/tab.

in the end I found an italian way to do it Smile

event script for the button on visu
Code:
url = storage.get('dashboard_url', 'https://www.google.com/')
lunghezza = string.len(url)
n=1
dashboard_url=''

for i = 1, lunghezza, 230 do
 
  blocco = string.sub(url, i, i+229)
 

 
  grp.write('33/2/'..n, blocco)
  log (i, blocco)
  sleep (0.5)
  sottostringa = grp.getvalue('33/2/'..n)
 
  dashboard_url = dashboard_url..sottostringa
 

  n= n +1
end


and  JS

Code:
  // Funzione per aggiornare l'URL una volta ricevuti tutti i blocchi
  function aggiornaUrl() {
   // if (blocco1 && blocco2 && blocco3 && blocco4) {
      url = blocco1 + blocco2 + blocco3 + blocco4;
   // }
  }

  // Listener per ogni indirizzo di gruppo
  grp.listen('33/2/1', function(obj) {
    blocco1 = obj.value;
    aggiornaUrl();
  });

  grp.listen('33/2/2', function(obj) {
    blocco2 = obj.value;
    aggiornaUrl();
  });

  grp.listen('33/2/3', function(obj) {
    blocco3 = obj.value;
    aggiornaUrl();
  });

  grp.listen('33/2/4', function(obj) {
    blocco4 = obj.value;
    aggiornaUrl();
  });
});


Best regards 

Peppe
Reply


Forum Jump: