IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#TechXchangePresenter
 View Only
  • 1.  Alert JavaScript

    Posted Tue August 20, 2013 05:07 PM

    Hello, i have a problem making an alert with javascript, when the user left the portlet and goes to another from the menu application the alert never pop up, is anyway to do this so i can alert to an user that it is leaving the portlet.? Thank you.


    #MWS-CAF-Task-Engine
    #webMethods-BPMS
    #webMethods


  • 2.  RE: Alert JavaScript

    Posted Tue August 20, 2013 05:13 PM

    Please provide as much information as possible regarding what you have already tried.


    #MWS-CAF-Task-Engine
    #webMethods
    #webMethods-BPMS


  • 3.  RE: Alert JavaScript

    Posted Tue August 20, 2013 05:18 PM

    I have this different script

     var changes = false;        
    window.onbeforeunload = function() {
    if (changes)
    {
    var message = "Are you sure you want to navigate away from this page?\n\nYou have started writing or editing a post.\n\nPress OK to continue or Cancel to stay on the current page.";
    if (confirm(message)) return true;
    else return false;
    }
    }

    and this one

    window.onunload=function(){alert("ok");};

    but one i leave the portlet nothing happen.


    #webMethods
    #webMethods-BPMS
    #MWS-CAF-Task-Engine


  • 4.  RE: Alert JavaScript

    Posted Tue August 20, 2013 05:21 PM

    Which version of MWS are you using?


    #webMethods
    #MWS-CAF-Task-Engine
    #webMethods-BPMS


  • 5.  RE: Alert JavaScript

    Posted Tue August 20, 2013 05:25 PM


  • 6.  RE: Alert JavaScript

    Posted Tue August 20, 2013 05:49 PM

    Ok. Try something like this:

    //register your custom handler if it is not already there.
    if (!window.YourUnloadHandler) {
    /**
    * YourUnloadHandler functions.
    */
    window.YourUnloadHandler = {
    // flag to workaround IE bugs
    skipNextUnload: false,
    
    /**
    * Click handler to detect phatom beforeunload events in ie.
    * @param {event} event Event.
    */
    skipUnloadForScriptUrls: function(event) {
    var H = YourUnloadHandler;
    var target = Event.findElement(event);
    // check if self, parent, or grandparent is a link
    for (var i = 0; i < 3 && target.tagName != "A" && target.parentNode; i++)
    target = target.parentNode;
    H.skipNextUnload = (/^(javascript|mailto|tel|fax|aim|geo)/.test(target.href));
    },
    
    /**
    * Onbeforeunload handler
    * @param {event} event Event.
    */
    unloadFn: function(event) {
    if (console)
    console.log("unloadFn called");
    
    var H = YourUnloadHandler;
    if (H.skipNextUnload) {
    if (console)
    console.log("skipped unload event");
    
    H.skipNextUnload = false;
    return;
    }
    
    alert("unloaded");
    }
    }
    
    
    // register your custom event handler
    Event.waitUntilLoaded(function() {
    var H = YourUnloadHandler;
    
    if (console)
    console.log("registering event handlers");
    
    //observer for full page reload
    Event.observe(window, "beforeunload", H.unloadFn);
    
    //observer for partial page reload
    OpenAjax.hub.subscribe("Noodle.page.unload", H.unloadFn);
    
    //special care to workaround IE wierdness.
    if (CAF.ie)
    Event.observe(document, "click", H.skipUnloadForScriptUrls);
    });    
    }

    #MWS-CAF-Task-Engine
    #webMethods
    #webMethods-BPMS


  • 7.  RE: Alert JavaScript

    Posted Tue August 20, 2013 06:02 PM

    It almost work, the one problem is that now when i change the portlet it pop up the alert in every portlet lol, i have to control that this behavior is only for one portlet.


    #webMethods-BPMS
    #webMethods
    #MWS-CAF-Task-Engine


  • 8.  RE: Alert JavaScript

    Posted Tue August 20, 2013 06:10 PM

    I just need to modify that javascript, so it only works in a specify portlet.


    #MWS-CAF-Task-Engine
    #webMethods-BPMS
    #webMethods