SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2002
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing a variable.

    so, I've found this popup code somewhere.
    HTML Code:
    <script language="javascript" type="text/javascript">
    <!--
    function popitup(url)
    {
    	newwindow=window.open(url,'name','height=200,width=150');
    	if (window.focus) {newwindow.focus()}
    	return false;
    }
    
    // -->
    HTML Code:
    <a href="popupex.html" onclick="return popitup('popupex.html')"
    	>Link to popup</a>
    what do I have to change so that I could pass the height and weight from the <a> link to the function? Right now it is set to a fix height/weight, since I am using various sizes, I have to pass it through the <a>.

  2. #2
    SitePoint Enthusiast Red Blaze's Avatar
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using the get method:
    example:
    HTML Code:
    pagename.php?h=100&w=100
    And in your javascript do this

    PHP Code:
    <script language="javascript" type="text/javascript"> <!-- function popitup(url) { newwindow=window.open(url,'name','height=<?php echo $_GET['h']; ?>,width=<?php echo $_GET['w']; ?>'); if (window.focus) {newwindow.focus()} return false; } // -->
    The pagename file (pagename being the name you choose) would have to be PHP.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2002
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, that is similar to what I want to do, but I don't want to instead assign the height/weight at the <a> link and not in the function because my php script doesn't start till after the body and not at the header.

    since i'm using Mysql, if I were to use your example, I would have to adjust my current php scripts.

  4. #4
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function popitup(url, h, w) { 
    	
    	var properties = 'height='+h;
    	properties += ',width='+w;
    	
    	newwindow = window.open(url,'name',properties);
    	
    	if (window.focus) {
    		newwindow.focus()
    	}
    	
    	return false; 
    }
    HTML Code:
    <a href="popupex.html" onclick="return popitup(this.href, '300', '300')">Link to popup</a>
    Add two parameters to the function and pass two arguments to the function. Concatenate the properties string and pass that to the window.open() method of the window object.


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
  •