0

When the popup opens I have four images with the onclick event this event will call an existing function in a js file but I'm not able to call the js function at all. How to load a js file along with the popup being created?

 $( document ).on( "pagecreate", "#page", function() {
            $( ".webcams" ).on( "click", function() {
                var target = $( this ),
                    brand = target.find( "h2" ).html(),
                    model = target.find( "p" ).html(),
                    port = target.find( "p1" ).html(),
                    short = target.attr( "id" ),
                    closebtn = '<a href="#" data-rel="back" class="ui-btn ui-corner-all ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a>',
                    header = '<div data-role="header"><h2>' + brand + ' ' + model + '</h2></div>',
                    img = '<img id="buffer" alt="" /><div style="width:0px; height:0px; overflow:hidden;"><img id="video" alt="" /><a href="#"><img src="img/left.png" style="overflow:hidden; position:absolute; left:4px; top:244px; width:55px; height:55px; background:none;" onclick="**sendirections("left",' + port + ')**" id="left" alt="" title="" /></a><a href="#"><img src="img/up.png" style="overflow:hidden; position:absolute; left:296px; top:44px; width:55px; height:55px; background:none; " id="up" alt="" title="" /></a><a href="#"><img src="img/down.png" style="overflow:hidden; position:absolute; left:296px; top:460px; width:55px; height:55px; background:none; " id="down" alt="" title="" /></a><a href="#"><img src="img/right.png" style="overflow:hidden; position:absolute; left:581px; top:244px; width:55px; height:55px; background:none; " id="right" alt="" title="" /></a></div>',
                    popup = '<div data-role="popup" id="popup-' + short + '" data-short="' + short +'" data-theme="none" data-overlay-theme="a" data-corners="false" data-tolerance="15"></div>';

                // Create the popup.  
                $( header )
                    .appendTo( $( popup )
                        .appendTo( $.mobile.activePage )
                        .popup() )
                    .toolbar()
                    .before( closebtn )
                    .after( img );

                // Wait with opening the popup until the popup image has been loaded in the DOM.
                // This ensures the popup gets the correct size and position
                $( ".photo", "#popup-" + short ).load(function() {
                    // Open the popup
                    $( "#popup-" + short ).popup( "open" );

                    // Clear the fallback
                    clearTimeout( fallback );
                });

                // Fallback in case the browser doesn't fire a load event
                var fallback = setTimeout(function() {
                    $( "#popup-" + short ).popup( "open" );
                }, 2000);

                var mjpegImg = 'http://address:' + port + '/';
                $('#buffer').load(function() {
                $('#video').attr('src', this.src);
                this.src = mjpegImg + '?cache=' + new Date().getTime();
                }).trigger('load', 1);


            });

            // Set a max-height to make large images shrink to fit the screen.
            $( document ).on( "popupbeforeposition", ".ui-popup", function() {
                var image = $( this ).children( "img" ),
                    height = image.height(),
                    width = image.width();

                // Set height and width attribute of the image
                $( this ).attr({ "height": height, "width": width });

                // 68px: 2 * 15px for top/bottom tolerance, 38px for the header.
                var maxHeight = $( window ).height() - 68 + "px";

                $( "img.photo", this ).css( "max-height", maxHeight );
            });

            // Remove the popup after it has been closed to manage DOM size
            $( document ).on( "popupafterclose", ".ui-popup", function() {
                $( this ).remove();
                clearTimeout( refresh );
            });

}); 
jameshwart lopez
  • 2,993
  • 6
  • 35
  • 65
Rui Branco
  • 15
  • 8
  • Add a script element or use [$.getScript()](https://api.jquery.com/jquery.getscript/) – GillesC Dec 11 '16 at 13:04
  • 1
    Possible duplicate of [JQuery to load Javascript file dynamically](http://stackoverflow.com/questions/912711/jquery-to-load-javascript-file-dynamically) – GillesC Dec 11 '16 at 13:06

0 Answers0