Quick Help with Random URL Popup Script

Discussion in 'JavaScript' started by matthewzachary, May 30, 2007.

  1. #1
    I am using a great script to generate a popup with randomized links however I am not sure how to customize the window.open to turn off the toolbar, scrollbars, status bar, resizing, etc..

    The beta page is http://ImTooYoungForThis.org/beta and the link in question is the one that opens the Jukebox.

    Here is the code:

    <SCRIPT LANGUAGE="JavaScript">
    var randomurls=new Array()
    randomurls[0]="popups/i2y_jukebox1.html"
    randomurls[1]="popups/i2y_jukebox2.html"
    randomurls[2]="popups/i2y_jukebox3.html"
    randomurls[3]="popups/i2y_jukebox4.html"
    randomurls[4]="popups/i2y_jukebox5.html"
    randomurls[5]="popups/i2y_jukebox6.html"
    randomurls[6]="popups/i2y_jukebox7.html"

    function randomurl(){
    window.open(randomurls[Math.floor(Math.random()*randomurls.length)]);
    }
    </script>

    <a class="linkopacity" href="javascript:randomurl()"><img src="images/jukebox.gif" border="0" width="420" height="148" alt="signup" align="top" style="border:1px #BFBFBF solid"></a>

    Thanks for any assistance.

    Matthew Zachary
     
    matthewzachary, May 30, 2007 IP
  2. DavidMerrilees

    DavidMerrilees Guest

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here's a script I wrote to manage pop up windows:

    
    popUp.prototype.ref = { closed : false, open : false };
    function popUp(url, name, opts) {
    	this.opts = opts;
    	this.url = url;
    	this.name = name;
    }
    
    popUp.prototype.open = function(reload) {
    	if (this.ref.closed || !this.ref.open || reload) this.ref = window.open(this.url, this.name, this.opts);
    	this.ref.focus();
    }
    
    HTML:
    I think it's neat because you can create pop up windows, find out whether they are still open or closed, have been opened at all (both the closed and open properties are false), control whether the pop up should reload, change the url to be opened and it ensures the pop up always receives focus when the open method is called.

    To use this script to create a pop up with no status bar etc. do the following

    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" >
    	<head>
    		<title>
    			make a pop up with no trimmings
    		</title>
    		<script type="text/javascript">
    			popUp.prototype.ref = { closed : false, open : false };
    			function popUp(url, name, opts) {
    				this.opts = opts;
    				this.url = url;
    				this.name = name;
    			}
    
    			popUp.prototype.open = function(reload) {
    				if (this.ref.closed || !this.ref.open || reload) this.ref = window.open(this.url, this.name, this.opts);
    				this.ref.focus();
    			}
    
    			var randomurls = new Array()
    				randomurls[0] = "blank1.html"
    				randomurls[1] = "blank2.html"
    				randomurls[2] = "blank3.html"
    
    			var MattsPopUp = new popUp("", "MattsWin", "height=200, width=400, status=yes, resizeable=no, toolbar=no, menubar=no, location=no");
    			popUp.prototype.randomUrl = function() {
    				this.url = randomurls[Math.floor(Math.random() * randomurls.length)];
    				this.open(true);
    			}
    		</script>
    	</head>
    	<body>
    		<a href="javascript:MattsPopUp.randomUrl(true)">test</a>
    	</body>
    </html>
    
    
    HTML:
     
    DavidMerrilees, May 31, 2007 IP