JAVASCRIPT CREW v.popup

Discussion in 'OT Technology' started by MSTRMOO, Jul 10, 2007.

  1. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
    ok so i have a php file called item.php, which also loads with attributes like "item.php?item=37&cat=1".. this php file also contains the following script..

    Code:
    <script language="javascript">
    
    
    
    function newWin(){
    var w=800;
    var h=600;
    var l=(screen.width-w)/2; if(l<0) l=0;
    var t=(screen.height-h)/2-50; if(h<0) h=0;
    window.open("item2.php","","left="+l+",top="+t+",width="+w+",height="+h+",toolbar=0,resizable=0,location=0,status=0,menubar=0,directories=0");
    }
    
    
    
    window.onload = newWin;
    
    </script>
    this opens item2.php in a popup window.. the problem is, i need it to open item2.php with the same attribute as item.php (eg. if the url of item.php is "item.php?item=37&cat=1" then item2.php should open with "item2.php?item=37&cat=1")

    how is this done?
     
  2. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    $_SERVER['QUERY_STRING'] should contain everything sent after the ?

    So:

    Code:
    window.open("item2.php<?=$_SERVER['QUERY_STRING']?>","","left="+l+",top="+t+",width="+w+",height="+h+",toolbar=0,resizable=0,location=0,status=0,menubar=0,directories=0");
    
    should work.
     
  3. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
    :bowdown: nice it works.. one more thing how would i go about closing item.php after item2.php opens?
     
  4. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    You can do a window.close but the visitor will be prompted with something like "Ieee, this website is trying to close your browser window, is it okay?" so I'd recommend against it.
     
  5. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
  6. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
    or actually no wait.. theres a better way around this. one sec
     
  7. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
    it would be alot better if this worked..

    i have this javascript
    Code:
    <script language="javascript">
    
    
    
    function newWin(){
    var w=800;
    var h=600;
    var l=(screen.width-w)/2; if(l<0) l=0;
    var t=(screen.height-h)/2-50; if(h<0) h=0;
    window.open("item2.php?<?=$_SERVER['QUERY_STRING']?>","","left="+l+",top="+t+",width="+w+",height="+h+",toolbar=0,resizable=0,location=0,status=0,menubar=0,directories=0");
    }
    
    
    </script>
    
    and this php script (its only a part of it obviously)

    Code:
    echo "<span class=\"gElement\"><a href=\"[B]javascript:newWin();[/B]\">".thumb(stripslashes($fetch['pic1']) ,stripslashes($fetch['brand']))."</a></br>".stripslashes($fetch['brand'])."</span>";
    this would open a popup without redirecting to another window etc etc.. so its simpler..

    but the problem now is.. the link is on a page like "stuff.php?cat=1".. so the popup would go to "item2.php?cat=1".. thats no good since there is no "item id" therefore the page will be blank (i would need it to go to something like item2.php?item=23&cat=1").

    the image the user clicks on is coming from a mysql database.. and that image has an item "id" attached to it.. heres the original script for that

    Code:
    echo "<span class=\"gElement\"><a href=\"item.php?item={$fetch['id']}&cat={$fetch['category']}\" target=\"_blank\">".thumb(stripslashes($fetch['pic1']) ,stripslashes($fetch['brand']))."</a></br>".stripslashes($fetch['brand'])."</span>";
    (this works, but its not a popup)

    soooo i need to somehow add "?item=##" to the popup link.. i have had no luck yet..
     
  8. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Why are you opening multiple popups with the same content? You're not one of those assholes who makes me have to close popup ads multiple times, are you?
     
  9. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
    refer to post #7.. im actually not very good with java or php.. espesially java IN php.. so i was looking for a way around that.. but i know theres a better way to do it.. hence why im asking
     
  10. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
    so basicly what im asking is..

    what do i add to this:

    window.open("item2.php?<?=$_SERVER['QUERY_STRING']?>","","left="+l+",top="+t+",width="+w+",height="+h+",toolbar=0,resizable=0,location=0,status=0,menubar=0,directories=0");

    or this

    echo "<span class=\"gElement\"><a href=\"javascript:newWin();\">".thumb(stripslashes($fetch['pic1']) ,stripslashes($fetch['brand']))."</a></br>".stripslashes($fetch['brand'])."</span>";

    to make the link include the item # (id)
     
  11. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
  12. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    I'm not exactly sure what you're asking.

    If you reference a PHP page like:

    item2.php?id=5&cat=1

    then the $_SERVER['QUERY_STRING'] contains the "query string" (everything after the ?). When a query string is sent to item2.php you get a key=value set for each.. set. id = 5 and cat = 1.

    These key/value sets are plopped into $_REQUEST (and $_GET and $_POST, where applicable).

    So if you did:

    Code:
    $id = $_REQUEST['id'];
    $cat = $_REQUEST['cat'];
    
    Then you'd have the data sent via the query string.
     
  13. MSTRMOO

    MSTRMOO Active Member

    Joined:
    Jul 19, 2005
    Messages:
    36,312
    Likes Received:
    0
    maybe this will explain it better.. here's the page

    http://www.prestigehomedesign.com/flooring.php?cat=1

    when you click on one of the images, i need a popup to appear with the item... however, $_SERVER['QUERY_STRING'], does not get the item number, but only the category in the url..
     
  14. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    That's cuz you're not passing the item id to newWin:

    javascript code change (added id to function):
    Code:
    function newWin(id){
    var w=800;
    var h=600;
    var l=(screen.width-w)/2; if(l<0) l=0;
    var t=(screen.height-h)/2-50; if(h<0) h=0;
    window.open("item2.php?id=" + id + "&<?=$_SERVER['QUERY_STRING']?>","","left="+l+",top="+t+",width="+w+",height="+h+",toolbar=0,resizable=0,location=0,status=0,menubar=0,directories=0");
    }
    
    span code change (added id [i assumed it's in $fetch]):
    Code:
    echo "<span class=\"gElement\"><a href=\"javascript:newWin(" . $fetch['id'] . ");\">".thumb(stripslashes($fetch['pic1']) ,stripslashes($fetch['brand']))."</a></br>".stripslashes($fetch['brand'])."</span>";
    
     
  15. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Just making sure.
     

Share This Page