Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Detecting if popups are blocked?

    Hi,

    Is there any way within the SmartGWT framework to detect if the user's browser has blocked popups, when they try to open a new tab when clicking on a button/link inside of SmartGWT?

    #2
    No,we don't provide a built-in function to detect pop-up blocking. By googling a bit you can find lots of advice and approaches.

    Comment


      #3
      Thanks, I ended up using a JSNI approach. This is my code in case anyone else could find it useful:

      Code:
      public native static boolean openPopupAndCheckBlocker(String url) /*-{
      
              var popupBlockerChecker = {
                  check: function(popup_window){
                      var _scope = this;
                      if (popup_window) {
                          if(/chrome/.test(navigator.userAgent.toLowerCase())){
                              setTimeout(function () {
                                  _scope._is_popup_blocked(_scope, popup_window);
                               },200);
                          }else{
                              popup_window.onload = function () {
                                  _scope._is_popup_blocked(_scope, popup_window);
                              };
                          }
                      }else{
                          _scope._displayError();
                      }
                  },
                  _is_popup_blocked: function(scope, popup_window){
                      if ((popup_window.innerHeight > 0)==false){ scope._displayError(); }
                  },
                  _displayError: function(){
                      alert("Popup Blocker is enabled! Please add this site to your exception list.");
                  }
              };
              var popup = window.open(url, '_blank');
              popupBlockerChecker.check(popup);
              return;
          }-*/;

      Comment

      Working...
      X