SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a script that will display random pop ups?

  2. #2
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you talking about a random alert box?
    You could use the script at http://javascript.internet.com/messages/rqt-puns.html
    as a starting point. You could put the script into a function if you need to call it at a particular point, and change the document.write(quote) to an alert(quote).

    If you're talking about a random popup window, this script would accomplish the same thing with some modifications.

  3. #3
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am talking about a pop up window, not a pop up alert box. I will check out that site, but I must tell you I don't know anything about Javascript.

  4. #4
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here it is, modified for a random popup.

    <html>
    <head>
    <title>Random Popup</title>

    <script language="JavaScript">
    <!--
    function openRandom() {

    pageURL = new Array
    pageURL[0] = "www.dell.com"
    pageURL[1] = "www.google.com"
    pageURL[2] = "www.yahoo.com"
    pageURL[3] = "www.webmonkey.com"
    pageURL[4] = "www.sitepoint.com"
    pageURL[5] = "www.altavista.com"
    pageURL[6] = "www.go.com"
    pageURL[7] = "www.cnn.com"
    pageURL[8] = "www.news.com"
    pageURL[9] = "www.apple.com"
    pageURL[10] = "www.ebay.com"

    randNum = Math.round(Math.random()*(pageURL.length-1));
    var thePage = pageURL[randNum];
    popupWin = window.open('http://' + thePage, 'myWindow', 'menubar,toolbar,location,directories,status,scrollbars,resizable,width=640,height=480');
    popupWin.focus();
    }
    // -->
    </script>
    </head>

    <body>

    <a href="#" onClick="openRandom();">Random Popup</a>

    </body>
    </html>

  5. #5
    HI silver trophy Silverado4x4's Avatar
    Join Date
    Jan 2001
    Location
    USA
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect! Thank You!

  6. #6
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    You shoudl always use Math.floor() (or Math.ceil), but nto Math.round() for Math.random() and random numbers. Explanation can be found here:

    http://javascriptcity.com/forums/sho...?threadid=2366

    So, use this:

    randNum = Math.floor(Math.random()*(pageURL.length));

    aDog


Bookmarks

Posting Permissions

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