Topic
  • 2 replies
  • Latest Post - ‏2013-11-27T22:58:50Z by RichardM90
RichardM90
RichardM90
5 Posts

Pinned topic RUI and custom browser events

‏2013-11-25T17:57:51Z |

I've read on a number of posts that people have captured additional events not associated with individual wizards but with the browser.

I don't know how I'd do this and can't see any examples that would get me started.

I'd like to handle both the browser resize and close events.

Can anyone either share or point me to some sample code?

Richard

 

  • dan_darnell
    dan_darnell
    973 Posts

    Re: RUI and custom browser events

    ‏2013-11-26T17:34:34Z  

     

    externalType BrowserFunctions extends Widget type JavaScriptObject {
        relativePath = "com/xxxxxxxx/custom/widgets",
        javaScriptName = "BrowserFunctions" }
        
        function setOnBeforeUnloadFunction(functionRef BeforeUnloadFunction);
    end
     

    egl.defineClass(
        'com.xxxxxx.custom.widgets', 'BrowserFunctions',                            
    {    
            "setOnBeforeUnloadFunction" : function (functionRef) {
                window.onbeforeunload=functionRef;
            }

    });
     

    Then, in your EGL RUIHandler or RUIWidget application code:

        browserFunctions BrowserFunctions{};
        

        // Initialization function
        function start()

            // Register the listener function
            browserFunctions.setOnBeforeUnloadFunction(onBeforeUnload);

        end    
        
        private function onBeforeUnload()
            
            // Do something before the browser goes away
            
        end
        
     

  • RichardM90
    RichardM90
    5 Posts

    Re: RUI and custom browser events

    ‏2013-11-27T22:58:50Z  

     

    externalType BrowserFunctions extends Widget type JavaScriptObject {
        relativePath = "com/xxxxxxxx/custom/widgets",
        javaScriptName = "BrowserFunctions" }
        
        function setOnBeforeUnloadFunction(functionRef BeforeUnloadFunction);
    end
     

    egl.defineClass(
        'com.xxxxxx.custom.widgets', 'BrowserFunctions',                            
    {    
            "setOnBeforeUnloadFunction" : function (functionRef) {
                window.onbeforeunload=functionRef;
            }

    });
     

    Then, in your EGL RUIHandler or RUIWidget application code:

        browserFunctions BrowserFunctions{};
        

        // Initialization function
        function start()

            // Register the listener function
            browserFunctions.setOnBeforeUnloadFunction(onBeforeUnload);

        end    
        
        private function onBeforeUnload()
            
            // Do something before the browser goes away
            
        end
        
     

    Hi Dan,

    Many thanks for that, it was enough to point me in the right direction and along with the HistoryHelper.js code I got it working.

    Anyway, I've added event captures for both window.onbeforeunload and window.onresize to my own BrowserLib I've been building, attached. This was built on EDT 0.8.2 but I'd imagine the code should be transferable. There is a BrowserSample RUI handler that showcases a lot of the features of the library, including the two new event handlers. I'd imagine the  handler will take a bit of work to make it non-EDT compatible.

    There's all sorts in the project including code to handle HTML5 local storage, getting and setting cookie values, setting the favicon, getting the browser sizes, etc.

    I've performed limited testing of the onresize events in Chrome and Firefox and they appear to work fine. I haven't tested them in IE and from what I've read about the onresize event in IE it seems to trigger on every mouse movement as your drag the borders to resize so you may need to code around this.

    Richard

    Attachments