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.

close window
#1
Hello,

Does anyone know any script that can execute the Ctrl + W command from a group address?
Reply
#2
If using Firefox you can set allow_scripts_to_close_windows to true in about:config
Then you can call window.close() in Custom JavaScript when a certain event occurs or attach it to a button click handler.
Reply
#3
(11.02.2019, 07:44)admin Wrote: If using Firefox you can set allow_scripts_to_close_windows to true in about:config
Then you can call window.close() in Custom JavaScript when a certain event occurs or attach it to a button click handler.


In this case I'm using Google Chrome, how can I do it?
Reply
#4
You can use this extension in Chrome: https://chrome.google.com/webstore/detai...jkhdjelmkb

You need to run Chrome via a shortcut in kiosk mode:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --kiosk http://192.168.1.10/scada-vis

Then you can close window by using this code:
Code:
window.location.href = '/closekiosk';
Reply
#5
(11.02.2019, 08:06)admin Wrote: You can use this extension in Chrome: https://chrome.google.com/webstore/detai...jkhdjelmkb

You need to run Chrome via a shortcut in kiosk mode:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --kiosk http://192.168.1.10/scada-vis

Then you can close window by using this code:
Code:
window.location.href = '/closekiosk';

thanks for the attention, how can I invoke that method from a group address?
Reply
#6
You can use this Custom JavaScript to close the window when 1/1/1 value changes:
Code:
$(function(){
  if (typeof grp === 'object') {
    grp.listen('1/1/1', function(obj, state) {
      if (state == 'value') {
          window.location.href = '/closekiosk';
      }
    });
  }
});

Keep in mind that this code might run in case disconnect happens so a better solution is to use Link element with External link mode and External link set to /closekiosk
Reply
#7
(11.02.2019, 09:00)admin Wrote: You can use this Custom JavaScript to close the window when 1/1/1 value changes:
Code:
$(function(){
 if (typeof grp === 'object') {
   grp.listen('1/1/1', function(obj, state) {
     if (state == 'value') {
         window.location.href = '/closekiosk';
     }
   });
 }
});

Keep in mind that this code might run in case disconnect happens so a better solution is to use Link element with External link mode and External link set to /closekiosk

Thank you very much, I get a 404 error, to see if I can see the problem, thank you very much for the help ...
Reply
#8
Check that extension is installed and enabled
Reply
#9
(11.02.2019, 09:41)admin Wrote: Check that extension is installed and enabled

Yes, I have put it in the java script editor, but it does not run well, because you would not know how to do the same but to write the command "ctrl + w" with this I would solve it ...
Reply
#10
grp.listen will execute only on object value change, so to trigger this you would need to turn it off then on again. This is why you should use Link element instead of Object.
Reply
#11
(11.02.2019, 10:32)admin Wrote: grp.listen will execute only on object value change, so to trigger this you would need to turn it off then on again. This is why you should use Link element instead of Object.

Do you know any script that can incorporate in the additional class of that link element that the order that you send is to close the window?
Reply
#12
You can use the same script, but you need an additional control object.
1. Create a virtual object (32/1/1 in this example)
2. Replace 1/1/1 with virtual object address in Custom JavaScript code
3. Create another object for control.
4. Attach an event script to control object:
Code:
if event.getvalue() then
  grp.write('32/1/1', false)
  grp.write('32/1/1', true)
end

This way sending on to control object will force value toggle for the virtual object. And this will execute close window via extension sequence.
Reply
#13
(11.02.2019, 10:58)admin Wrote: You can use the same script, but you need an additional control object.
1. Create a virtual object (32/1/1 in this example)
2. Replace 1/1/1 with virtual object address in Custom JavaScript code
3. Create another object for control.
4. Attach an event script to control object:
Code:
if event.getvalue() then
 grp.write('32/1/1', false)
 grp.write('32/1/1', true)
end

This way sending on to control object will force value toggle for the virtual object. And this will execute close window via extension sequence.

How would the complete script be in this case?
Reply
#14
Which one? You need to add code to Custom JavaScript and create an event script for control object.
Reply
#15
(11.02.2019, 11:33)admin Wrote: Which one? You need to add code to Custom JavaScript and create an event script for control object.

I've done it that way, and it does not work ...
Reply
#16
I tried it and it does work every time,
------------------------------
Ctrl+F5
Reply
#17
(11.02.2019, 12:08)Daniel. Wrote: I tried it and it does work every time,

because I can not get it to work for me, can you send me your script?
Reply
#18
(11.02.2019, 14:06)Daponte Wrote:
(11.02.2019, 12:08)Daniel. Wrote: I tried it and it does work every time,

because I can not get it to work for me, can you send me your script?

I used the one Admin posted without any change.  Maybe your issue is in correct installation of the extension?  In Chrome I just went to Visualization then More tools->Create shortcut.  Open visu via this shortcut.  I used Firefox to connect to LM and changed object 1/1/1.  Make sure it is Boolean.
------------------------------
Ctrl+F5
Reply
#19
Hi all,

I found a workaround to use the Javascript close() function so it's possible to close the visualization from a group address.
Since this function only works if the window was also opened by script we need to do this first.

First you need to add a startpage to your webbrowser using the Javascript code below as the url for the startpage.

javascript:window.open('192.168.0.10/scada-vis/','_self')

Then second you can use the script below as a Custom Javascript to close your visualization from the group address used in this script.

$(function(){
  if (typeof grp != 'undefined') {
    grp.listen('0/0/1', function(object, state) {
      var value = object.value;
      if (state == 'value') {
         window.close();
      }
    });
  }
});
Reply


Forum Jump: