www.webdeveloper.com
Results 1 to 2 of 2

Thread: Need help editing my first popup script

  1. #1
    Join Date
    Mar 2010
    Posts
    701

    Unhappy Need help editing my first popup script

    <script language="javascript" type="text/javascript">
    var numberOpen = 1

    //this causes a random statement to appear
    function banner() { } ; b = new banner() ; n = 0
    b[n++]= "Haha"
    b[n++]= "ROFL"
    b[n++]= "LoL"
    b[n++]= "LMAO"
    b[n++]= "Jokes"
    b[n++]= "Don't get pissed"
    b[n++]= "Don't close your computer"
    b[n++]= "I love Javascript"
    i=Math.floor(Math.random() * n) ;
    var randomDiss = ( b[i] )

    //different things happen depending on the number of times a new window is opened
    if (numberOpen == 1) {
    var popUp = window.open('http://fancyguppy.webs.com/javascript/onload&#37;20onunload.html','numberOpen');
    }
    else {
    if (numberOpen >= 2 && numberOpen <= 4) {
    document.write("LoL, now you can't close it. Don't worry, keep trying, you'll find a way :P");
    var popUp = window.open('http://fancyguppy.webs.com/javascript/onload%20onunload.html');
    }
    else {
    if (numberOpen >= 5 && numberOpen <= 10) {
    document.write(randomDiss + ", keep trying!");
    var popUp = window.open('http://fancyguppy.webs.com/javascript/onload%20onunload.html');
    }
    else {
    if (numberOpen >= 11) {
    var popUp = document.write("Try minimizing everything, then closing the windows one by one.");
    }
    else {
    var popUp = document.write("Something went wrong, tell me (Leo J.) about it");
    }
    }
    }
    }

    function openLoop() {
    numberOpen++;
    var returnThis = popUp;
    return returnThis;
    }
    </script>

    <body onUnload="openLoop()">
    It can be found here: http://fancyguppy.webs.com/javascrip...0onunload.html . I want a new window to open each time the previous window closes. By the 11th time a window is opened, no more windows will open. However, if you tried it, you'll realize that it isn't working properly. Can someone please help me?

    Thanks in advance.
    Last edited by narutodude000; 03-25-2010 at 07:07 PM.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Using document.write after the page loads creates a new document, hence numberOpen will always be 1.
    Use a window reference to open a window and write to that window.

    Your present site forces the user to close the browser in order to break out of the loop. This is abuse and could get you blacklisted.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles