简体   繁体   中英

Popup opening multiple time in jquery

i am working on script where i have to open pop up after click on window . but after click on window the function executing twice .How to resolve this ? ie after click on window two popup opening . but after click on function the function executing twice

 <!doctype html>
        <html lang="en">
            <head>
            <meta charset="UTF-8">
        <title>Best Popunder Script Ever @ ScratchingCodes.com</title>
            <meta name="description" content="Best Popunder Script Ever Demo and Download" >
            <meta name="author" content="Mr. Farhan Saleem ">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <link rel="stylesheet" type="text/css" href="css/style.css">
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
            </head>
            <body>
        <div id="testSubmit" >
        <header class="txt-center">
              <h1>Best Popunder Script Ever Demo and Download</h1>
              <br>
              <h3>Please click on Button</h3>

              <form action="">
                <input type="submit" />
            </form>


            <script type="text/javascript">
               (function($) {
                $.popunder = function(sUrl) {
                    var bSimple = $.browser.msie,
                        run = function() {
                            $.popunderHelper.open(sUrl, bSimple);
                        };
                    (bSimple) ? run() : window.setTimeout(run, 1);
                    return $;
                };
                $.popunderHelper = {

                    rand: function(name, rand) {
                        var p = (name) ? name : 'pu_';
                        return p + (rand === false ? '' : Math.floor(89999999*Math.random()+10000000));
                    },

                    open: function(sUrl, bSimple) {
                        var _parent = self,
                            sToolbar = (!$.browser.webkit && (!$.browser.mozilla || parseInt($.browser.version, 10) < 12)) ? 'yes' : 'no',
                            sOptions,
                            popunder;

                        if (top != self) {
                            try {
                                if (top.document.location.toString()) {
                                    _parent = top;
                                }
                            }
                            catch(err) { }
                        }

                        sOptions = 'toolbar=' + sToolbar + ',scrollbars=yes,location=yes,statusbar=yes,menubar=no,resizable=1,width=800,height=510';
                        sOptions += ',height=' + (screen.availHeight - 122).toString() + ',screenX=0,screenY=0,left=0,top=0';


                        var a =  $('#dialog').clone().html();
                        var  popunder = _parent.window.open(sUrl, $.popunderHelper.rand(), sOptions);
                        var yourDOCTYPE = "<!DOCTYPE html>"; 
                        var printPreview = _parent.window.open('about:blank', 'print_preview', "menubar=1,resizable=1,width=1024,height=600");
                        var printDocument = printPreview.document;
                        printDocument.open();   
                        printDocument.write(yourDOCTYPE+    "<html>"+ a + "</html>");


                        if (popunder) {
                            popunder.blur();
                            if (bSimple) {
                                window.focus();
                                try { opener.window.focus(); }
                                catch (err) { }
                            }
                            else {
                                popunder.init = function(e) {
                                    with (e) {
                                        (function() {
                                            if (typeof window.mozPaintCount != 'undefined' || typeof navigator.webkitGetUserMedia === "function") {
                                                var x = window.open('about:blank');
                                                x.close();
                                            }

                                            try { opener.window.focus(); }
                                            catch (err) { }
                                        })();
                                    }
                                };
                                popunder.params = {
                                    url: sUrl
                                };

                                popunder.init(popunder);
                            }
                        }

                        return true;
                    }
                };

            })(jQuery);

            $(window).unbind().click(function() {

               jQuery.popunder('#');
               console.log('ok');
            });
            </script>
            </header>
                     <div id="dialog" class="window">
                       My Window Content
                     <div id="popupfoot">
                     <a href="#" class="close agree" id="close">
                     <i class="fa fa-times"></i>
                     </a>
                     </div>
                     </div> 

        <p class="txt-center" style="font-size:14px;"  >
        <img src="http://scratchingcodes.com/wp-content/uploads/2015/05/Scratching-codes-logo-orange1.png">
        <br>
              <a href="http://scratchingcodes.com/best-jquery-popunder-script-for-chrome">Back to the post </a> </p>
        <br>
        <footer class="txt-center"> Designed and Developed by <a href="http://scratchingcodes.com/" > Scratching Codes </a> </footer>
        </div>
        </body>
        </html>

Why don't you use the Bootstrap Modal?

http://getbootstrap.com/javascript/#modals

your concept of clicking on window and opening the popup is wrong , every time you click on any element the window will popup , which is very disturbing thing , you should implement some trigger for opening the popup , or specify why you want this to be happen.

like to your :

<input type="submit" />

give an id or a class:

<input type="submit" id="open_popup"/>

then change your function from this:

$(window).unbind().click(function() {

               jQuery.popunder('#');
               console.log('ok');
            });

to this

$('#open_popup').click(function() {

               jQuery.popunder('#');
               console.log('ok');
            });

but till you don't provide the information about why and how you want it to react . can't help more

You could try this [pseudocode]

var flag = false;
on click do
   if flag === true;
      return false;
   flag = true;
   //do your stuff here
   flag = false
end click

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM