1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Annoying script

Discussion in 'HTML & JavaScript' started by Black&Red, Oct 23, 2011.

  1. Black&Red

    Black&Red Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 14, 2008
    Messages:
    445
    Likes Received:
    248
    Location:
    Latvia
    Is it still possible to make those annoying sites which are impossible to close? If yes could someone share some tips (for personal use only).

    Thanks
     
  2. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    Add as many messages as you want, at the end of the loop it will start back at message1 indefinately and keep on looping forever:
    Code:
    <script>
    var Messages = [
    	"Message1",
    	"Message2",
    	"Message3"
    	];
    i=0;
    while (i<Messages.length){
    	alert(Messages[i]);
    	i++;
    	if (i == Messages.length){
    		i=0;
    		}
    	}
    </script>
    
     
    • Thanks Thanks x 4
  3. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,147
    An optimization tip (not that it matters on this case, but it 's good for big scripts)

    Having Messages.length in the while test and on the loop will cause it to re-evaluate each time. So, it 's faster to do:
    Code:
    var len = Messages.length;
    while(i<len) {
    ...
    
    But even more, in this script the check in the while is unnecessary, since this would suffice:
    Code:
    var len = Messages.length;
    while(1) { /* For ever */
        for (i=0; i < len; i++) {
            alert(Messages[i]);
        }
    }
    
    These are micro-optimizations than are needed only in large projects but it 's good to keep in mind, as it 's training to think more efficiently.
     
    • Thanks Thanks x 2
  4. Fuggz

    Fuggz Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 25, 2010
    Messages:
    583
    Likes Received:
    600
    Add these script to <body onunload> to keep some functionality to your page. Using the scripts above with this technique will allow the user to use your site, but whenever they try to navigate away from your page (by pressing back button, clicking any external link or typing in a new URL) they will be bombarded by never ending alerts.
     
  5. Sprouts

    Sprouts Regular Member

    Joined:
    Mar 20, 2010
    Messages:
    461
    Likes Received:
    324
    Quite a few people use chrome and after a couple of these it has the option to "Stop this website from opening any more alerts"
     
  6. IGotta

    IGotta Junior Member

    Joined:
    Aug 27, 2010
    Messages:
    105
    Likes Received:
    41
    Occupation:
    Entrepreneur
    Location:
    Earth

    Same with firfox, it will show message 1, and all the other messages. After message 2 a little message underneath allows you to check the box to prevent additional dialogues and then it goes away.
     
  7. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    A possible workaround could be storing the current message that you are on in a variable and then onpageunload recall the script to start running again.
     
    • Thanks Thanks x 1