0

Years ago, I found this "fancy alert" popup box for use with jQuery mobile. I've been using it in my Cordova apps for years.

Recently, I've been informed that version 2.1.3 of jQuery has security holes, and I needed to upgrade. The newest version of jQuery that works with jQuery Mobile is 2.2.4. So I have upgraded to 2.2.4, but it breaks my "fancy alert" popup box.

Here's my code:

function fancyAppAlert(alertContent){
    if ($("#fancyAlertPopup").length === 0) {
        $(':mobile-pagecontainer').pagecontainer('getActivePage').append('<div style="padding-top: 10px; ' +
            'padding-bottom: 20px; padding-left: 20px; padding-right: 20px; width: 86%" data-role="popup" ' +
            'id="fancyAlertPopup" data-theme="a" class="ui-content"><a href="#" data-rel="back" ' +
            'class="ui-btn ui-corner-all ui-shadow ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right">' +
            'Close</a><h4 id="fancyAlertText">' + alertContent + '</h4></div>').trigger("create");
    } else {
        $('#fancyAlertText').html(alertContent);
    }
    $("#fancyAlertPopup").popup( "open",{transition: "flip"} );
}

When I use jQuery 2.1.3 the above code pops up an alert window that displays the contents of alertContent. When I use jQuery 2.2.4, the exact same code gives me the following error: Uncaught TypeError: Cannot read properties of undefined (reading 'trigger')

So clearly it's the .trigger("create") that's breaking it, but I have no idea why. I can find no documentation that mentions any breaking changes between version 2.1.3 and 2.2.4. Does anyone know how to fix this? I cannot upgrade to jQuery 3.x.x because I must have jQuery Mobile 1.4.5, and jQuery 3.x.x does not work with jQuery Mobile 1.4.5.

Thanks for any help you can give.

3
  • Ok... Weird... If I manually add that <div> to one of my pages, the $("#fancyAlertPopup).popup( "open", {transition: "flip") throws this error: jquery-2.2.4.js:5017 Uncaught TypeError: e.preventDefault is not a function Commented Feb 13, 2023 at 19:25
  • Can You please specify which popup library you are using? Using jQuery 2.2.4 & JQM 1.4.5 Your piece of code works for me without issues.
    – deblocker
    Commented Feb 14, 2023 at 12:32
  • Really? I tried for many, many hours to get it to work... Never could. When I switched back to jQuery 2.1.4, it started working fine. That .popup command is part of jQuery Mobile -- I'm not using any other libraries other than jQuery and jQuery Mobile... Commented Feb 16, 2023 at 4:19

1 Answer 1

0

Well, apparently jQuery 2.2.4 IS NOT compatible with jQuery Mobile 1.4.5. Apparently the latest version of jQuery that's compatible with jQuery Mobile is 2.1.4. That's seriously annoying...

Not the answer you're looking for? Browse other questions tagged or ask your own question.