Page 1 of 1

Block Browser Refresh

Posted: Mon Nov 15, 2010 9:48 am
by esdaled
Is there any way for Atrium to Block (or at least request confirmation) of a browser refresh initiated by the F5 key. From the 5250, our users are in the habit of using the F5 key to refresh a screen/page. When they are on a non-Genie web page in Atrium and they press F5, Atrium reloads and they have to sign back into Atrium.

Re: Block Browser Refresh

Posted: Mon Nov 15, 2010 6:10 pm
by David
Currently there is no option to do this in Atrium. We may add this feature in a future release.

In the meanwhile, a script running in any one of your pages launched in Atrium could assign such an event.

For example, if you are running Genie screens from Atrium, code in your "custom.js" file could do the work.

There is no way for a browser application to prevent the user from navigating away from the current page (makes sense if you think about it), but you can have the browser display a warning and force the user to confirm before this happens. The following code will do it:

Code: Select all


parent.onbeforeunload = function() {
  return "My message.";
}

If you are running Genie with the "confirm on close" or "auto disconnect" options in effect, Genie will be running in a frameset and you may need to use "parent.parent" as opposed to "parent".

The browser will force the user to confirm before navigating away. It will display 2 lines of standard text (which you cannot control), and it will place the string returned by your function in between those 2. If you want no message of your own, simply return an empty string from the function.

Re: Block Browser Refresh

Posted: Tue Nov 15, 2016 9:19 pm
by shuffman
Old thread i know... but i have the same issue and i think i have a solutions that works. I'm not a huge fan of the onbeforeunload event so i came up with this.

This is intended to disable all function keys when not inside an application that was launched from atrium and has only been tested in ProfoundUI v5.6 and Chrome v54.0.2840.99

In the atrium javascript extension located on the IFS at '/www/yourinstance/htdocs/profoundui/userdata/extension/atrium/settings.js' depending on your instance name.
Note: i believe the settings.js file needs to be created if it doesn't already exist. More info here: http://www.profoundlogic.com/docs/displ ... ecific+API
This is a function you can add to the atrium onload event to stop the function keys. If you're not already familiar with the settings.js extention of atrium you will only need to create the file and include this code. Otherwise just add the function and function call to the onload event.

Code: Select all

Atrium.onload = function() {
	disableFunctionKeys();
}

function disableFunctionKeys(){
	document.addEventListener("keydown",function(){
		var code = (event.keyCode ? event.keyCode : event.which);
		if(code >= 112 && code <= 123){
			event.preventDefault();
			event.keyCode = 0;
		}
	});
}
As an extra precaution: The atrium banner is located in it's own iframe and if the banner receives focus somehow by a user clicking on it etc... the function keys will still be triggered. I attemped to prevent this from the settings.js file but was unsuccessful. As a user this should rarely occur but If you need to you can include the following in your banner html file.

The default banner file is /www/yourinstance/htdocs/profoundui/userdata/html/atrium_banner.html

Add the following code within the <head></head> tags. Also, you may need to clear your browser cache after editing the banner. This may pose a problem for users that have it cached as well.

Code: Select all

<script type="text/javascript">
    //disable function keys
	window.onload = function() {
		document.addEventListener("keydown",function(){
			var code = (event.keyCode ? event.keyCode : event.which);
			if(code >= 112 && code <= 123){
				event.preventDefault();
				event.keyCode = 0;
			}
		});
	};

</script>
In conclusion, I was rather surprised that the web browser allowed me to override these function keys but i hope this will help someone.

Re: Block Browser Refresh

Posted: Wed Nov 16, 2016 12:40 am
by Scott Klement
Sam, thanks for the example.

I have two minor suggestions that you might consider:

1) Instead of naming the file "settings.js", I would consider calling it disableFunctionKeys.js (in the same directory). Using a name like that is a bit tidier, imho. Use settings.js for actual configuration options.

(Atrium will load any file in the extension/atrium directory, no matter what the name, as long as it ends in .js)

2) For your banner, why not link in the same file instead of repeating the code? You'd have to make some small changes so that Atrium.onload doesn't try to run when the Atrium APIs aren't there, but that's not hard to do.

Re: Block Browser Refresh

Posted: Wed Nov 16, 2016 1:19 am
by shuffman
Yes, that would be much cleaner.

So perhaps this would go in /www/yourinstance/htdocs/profoundui/userdata/extension/atrium/disableFunctionKeys.js

Code: Select all

window.addEventListener("load", function(){
	disableFunctionKeys();
});

function disableFunctionKeys(){
	document.addEventListener("keydown",function(){
		var code = (event.keyCode ? event.keyCode : event.which);
		if(code >= 112 && code <= 123){
			event.preventDefault();
			event.keyCode = 0;
		}
	});
}
and this in /www/yourinstance/htdocs/profoundui/userdata/html/atrium_banner.html

Code: Select all

<script type="text/javascript" src="/profoundui/userdata/extension/atrium/disableFunctionKeys.js"></script>
Thanks, this is much better. except now i'll need to go back and organize some of the other functions i should have done this way. :-S

Re: Block Browser Refresh

Posted: Thu Nov 09, 2017 6:32 am
by CAPL_INFO
Hi,

I set up this code and it does not work on the atrium home tab if i clik inside.
Do you know why ?

Thanks for yours replys

Re: Block Browser Refresh

Posted: Thu Nov 09, 2017 1:46 pm
by shuffman
It is because the homepage is a separate iframe.

Something like this might work. Note that i changed disableFunctionKeys() to have the document object be passed as a parameter.
The 3000 on the timeout allows 3 seconds for everything to load before trying to do anything.

Code: Select all

setTimeout(function(){
	var centerPanel = document.getElementById("Atrium-centerPanel");
	var frames = centerPanel.getElementsByTagName("IFRAME");
	for (var loopy = 0; loopy < frames.length; loopy++) {
		var currentFrame = frames[loopy];
		disableFunctionKeys(currentFrame.contentDocument);
	}
},3000);
	

Code: Select all

function disableFunctionKeys(theDocument){
	theDocument.addEventListener("keydown",function(event){
	      var code = (event.keyCode ? event.keyCode : event.which);
	      if(code >= 112 && code <= 123){
	         event.preventDefault();
	         event.keyCode = 0;
	      }
	});
}
	
if you replace the function you would also have to replace:

Code: Select all

window.addEventListener("load", function(){
   disableFunctionKeys();
});
with:

Code: Select all

window.addEventListener("load", function(){
   disableFunctionKeys(document);
});
The finished product would be a js file in /www/yourinstance/htdocs/profoundui/userdata/extension/atrium with this in it:

Code: Select all

setTimeout(function(){
   var centerPanel = document.getElementById("Atrium-centerPanel");
   var frames = centerPanel.getElementsByTagName("IFRAME");
   for (var loopy = 0; loopy < frames.length; loopy++) {
      var currentFrame = frames[loopy];
      disableFunctionKeys(currentFrame.contentDocument);
   }
},3000);

function disableFunctionKeys(theDocument){
	theDocument.addEventListener("keydown",function(event){
		var code = (event.keyCode ? event.keyCode : event.which);
	    if(code >= 112 && code <= 123){
	       event.preventDefault();
	       event.keyCode = 0;
	    }
	 });
}

window.addEventListener("load", function(){
	disableFunctionKeys(document);
});
minimally tested with PUI 5.6.0 and Google Chrome

I thought of one other thing. If the homepage is coming from a different domain it probably will not let you attach events to it.

Re: Block Browser Refresh

Posted: Thu Nov 09, 2017 3:01 pm
by Scott Klement
Assuming that the home page is a page that you can change, you could add code into the home page itself to block the F5 key.

Alternately, you could use Sam's solution, with the caveat that it won't work for the first 3 seconds ;-) And, as he mentioned, you will only have permission to change that child page from an Atrium extension file if it's from the same domain. If from a different one, the browser will block access to attach events to it.

Re: Block Browser Refresh

Posted: Fri Nov 10, 2017 4:19 am
by CAPL_INFO
Hi,

I added in my custom page that ...

Code: Select all

<script type="text/javascript" src="/profoundui/userdata/extension/atrium/disableFunctionKeys.js"></script>
and it works well !!!