#1
  1. No Profile Picture
    Demonic Swordsman DGQB
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Apr 2003
    Posts
    1,043
    Rep Power
    83

    Javascript function malfunction


    I have a simple function that doesn't work:

    Code:
    function popup(w)
    {
    	popup = window.open("../images/lidanSofa.jpg","lidanSofa","toolbar=no,width=w,height=503,status=no,scrollbar=no,resize=no,menubar=no");
    }
    Then in the html body, I call:
    Code:
    <a href="javascript:popup('33');">
    The function takes the var w and sets it as the width of the popup window. However, the variable doesn't become the width of the window. Can I not set a parameter, such as w, as the width?
  2. #2
  3. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    hi, vb.net...

    String: "toolbar=no,width=w,height=503,status=no,scrollbar=no,resize=no,menubar=no"

    String variable: w

    A little interpolation (JS != Perl) is needed:

    "toolbar=no,width="+w+",height=503....

    Kindly remove the from your link.
  4. #3
  5. No Profile Picture
    Got source?
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2003
    Location
    Laguna Niguel, California, USA
    Posts
    2,331
    Rep Power
    14
    Originally posted by adios

    Kindly remove the from your link.
    LOL. That can get kinda annoying.
  6. #4
  7. No Profile Picture
    Demonic Swordsman DGQB
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Apr 2003
    Posts
    1,043
    Rep Power
    83
    adios! thanks again. So now I have:

    Code:
    function popup(url, w, h)
    {
    	popup = window.open(url,"myWindow","toolbar=no,width="+w+",height="+h+",status=no,scrollbar=no,resize=no,menubar=no");
    }
    as you can see, the function takes 3 parameters: url, width, and height. And I call it in the html like this:

    Code:
    <a href="javascript: popup('../images/lidanChair.jpg','250','100');">
    And it works great - the first time you click on it. After that, the status bar says "error on page," and I can't get the popup any more UNLESS I reload the page. So why does work only ONCE per load? Did I do something wrong again?
  8. #5
  9. No Profile Picture
    Demonic Swordsman DGQB
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Apr 2003
    Posts
    1,043
    Rep Power
    83
    ah, I figured it out. I shouldn't have the same name for a function and a variable, like popup() and popup = window.open... It worked when I changed it to popup1 = window.open...
  10. #6
  11. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    function popup(url, w, h)....

    creates window.popup (property) containing function object

    {
    popup = window.open.....

    ...immediately over-writes the above with new window.popup assignment

    ...as you guessed. Your function destroyed itself!

IMN logo majestic logo threadwatch logo seochat tools logo