Search code examples
javascriptjqueryhtmljquery-mobile

Popup issue after upgrading jQuery from 1.11.1 to 3.3.1


I was using jQuery 1.11.1 and jQuery Mobile 1.4.5, everything is working fine. Recently I have upgraded jQuery to 3.3.1. I am getting popup issue. I am getting below error when i tried to open the popup in button onlick by calling popupCaptureOptions() function.

Uncaught TypeError: e.preventDefault is not a function
    at w.Event.preventDefault (jquery-3.3.1.min.js:2)
    at w.Event.preventDefault (jquery-3.3.1.min.js:2)
    at jquery.mobile-1.4.5.min.js:7
    at i (jquery-3.3.1.min.js:2)
    at dispatch (jquery-3.3.1.min.js:2)
    at y.handle (jquery-3.3.1.min.js:2)
    at Object.trigger (jquery-3.3.1.min.js:2)
    at jquery-3.3.1.min.js:2
    at Function.each (jquery-3.3.1.min.js:2)
    at jQuery.fn.init.each (jquery-3.3.1.min.js:2)

My html page looks like below.

 <div data-role="page" id="previewscreen">
        <main>
            <div data-role="main" class="ui-content" style="margin:0; padding:0;">
                <div id="ID_IMAGE_DIV" class="ID_IMAGE_DIV">
                </div>
            </div>
        </main>
        <div data-role="popup" data-history="false" data-overlay-theme="a" data-position-to="window" id="imagePopup">
            <a class="popup_refrence" href="#" data-rel="back"></a>
            <img id="popupImage" />
        </div>
        <div data-role="popup" data-dismissible="false" data-position-to="window" class="ui-content" id="ID_EXTRACTIONERRORPOPUP">
            <a href="#" id="cancel" class="ui-btn ui-corner-all ui-shadow ui-btn ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a>
            <p class='error'>Extraction Failed.</p>
            <div id="ID_MORETEXT"></div>
            <a id="ID_MORE" href="#">Read more</a>
            <p id="extractionfailed"></p>
        </div>
        <div data-role="popup" id="capture_popupalert" data-dismissible="false" data-position-to="window" class="ui-content" data-overlay-theme="b">
            <h4 style="text-align:center; margin-top:10px">Capture Options</h4>
            <hr style=" margin-top: 0;" />
            <div id="back_capture" style="margin-top:5%">
                <div class="ui-grid-a">
                    <a style="background-color:#00b3b3;color:white;margin-left:30px;margin-right:30px;" id="back_capture_button" class="ui-btn ui-corner-all ui-shadow">Capture Back</a>
                </div>
            </div>
            <div id="skip" style="margin-top:5%">
                <div class="ui-grid-a">
                    <a style="background-color:#00b3b3;color:white;margin-left:30px;margin-right:30px;" id="skip_button" class="ui-btn ui-corner-all ui-shadow">Skip</a>
                </div>
            </div>
        </div>
    </div>

My javascript code is

var popupCaptureOptions = function() {
        var imgFrontElement = document.getElementById("ID_IMAGE_DIV");
        var content_width = $.mobile.activePage.find("div[data-role='content']:visible:visible").outerWidth();
        $('#capture_popupalert').css({'width':content_width*0.8});
        $("#capture_popupalert").popup("open");
        $("#back_capture").click(function() {
            capturedSide = CAPTURESIDE.CAPTURE_BACK;
            doCapture();
        });

        $("#skip").click(function() {
            $("#capture_popupalert").hide();
            imgFrontElement.style.backgroundColor = "white";
            Utils.showLoadingIndicator();
            if (currentModule == Module.MOBILEID) {
                MobileIDModule.extractData(frontCapturedImage, backCapturedImage, isOnBoardingFlow, region);
            } else if (currentModule == Module.CHECK) {
                CheckDepositModule.extractData(frontCapturedImage, backCapturedImage, isOnBoardingFlow, region);
            }
            frontCapturedImage = null;
        });
    };

Please help me how can solve this issue.


Solution

  • It is very simple.

    jQuery Mobile 1.4.5 was not made to work with the latest jQuery versions.

    These are supported jQuery versions for jQM 1.4.5: jQuery 1.8 - 1.11 / 2.1

    More about them can be found here.

    So either upgrade to jQM 1.5 or use an older version of jQuery.