#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    39
    Rep Power
    13

    What's Wrong with this Javascript Code w/ PHP


    Hi guys, I have a link that I'd like to have open a small window so I wrote a window.open javascript command and call it like this:

    Code:
    <a href="javascript:window.open('viewproduct.php?id=<?= $linkid; ?>&s=<?= $session[sessionhash]; ?>','productinfo','width=500,height=350,scrollbars=yes,resizable=yes')">View Product Info</a>
    The pop up window comes up, but the main window goes to a screen which just says [object]. There's something I must be missing, but I couldn't catch it. Can anyone tell what may be causing this?

    [edit]I don't know why the javascript shows up as java script, but the code I pasted is not like that in the textbox.[/edit]

    Thanks,

    Mark
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Location
    Sydney, Australia
    Posts
    1
    Rep Power
    0
    try
    <a href="javascript: window.open('viewproduct.php?id=<?= $linkid; ?>&s=<?= $session[sessionhash]; ?>','productinfo','width=500,height=350,scrollbars=yes,resizable=yes');">View Product Info</a>
  4. #3
  5. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, I usually use the onclick event and return false to open new windows, but here's a snippet that will launch from the href and won't send the current window to a new link.
    Code:
    <html>
    <head>
    <script>
    function openIt() {
      window.open('xml.html');
      return;
    }
    </script>
    </head>
    <body>
    <a href="javascript: openIt();">click</a>
    </body>
    </html>
    You'll have to modify it to suit your purposes, of course
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    56
    Rep Power
    12
    Originally posted by bricker42
    Well, I usually use the onclick event and return false to open new windows, but here's a snippet that will launch from the href and won't send the current window to a new link.
    wouldn't the simple target="_blank" do that?
    Code:
    <a href="link.html" target="_blank">click me</a>
    PHP is fun
  8. #5
  9. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Nothing's wrong with it, but using window.open() you can specify the size of the window, whether it has scrollbars and buttons, and you can close it again from the main window.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    56
    Rep Power
    12
    isn't the no scroll bar thing just some tags put in the head with the rest of the style parts?
    PHP is fun
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    45
    Rep Power
    12
    HI !

    try to add in the end of link
    resizable=yes');void(0);">

    or create JS function in HTML code
    <script language="JavaScript">
    <!--
    function open_popup (url) {
    window.open(url,'productinfo','width=500,height=350,scrollbars=yes,resizable=yes');
    }
    //-->
    </script>
    and call from link
    <a href="javascript:open_popup('viewproduct.php?id=<? echo $linkid."&s=".$session[sessionhash]; ?>')>View Product Info</a>

    :)

    PS And don't forget to remove space from "java script" - this board insert it :)

IMN logo majestic logo threadwatch logo seochat tools logo