Thread: grrr javascript

    #1
  1. No Profile Picture
    =) wannabe?
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2002
    Location
    florida
    Posts
    2,153
    Rep Power
    15

    grrr javascript


    i dont get it



    there's no ; after window.open()

    but when i put the parent function in the link like "javascript:newWin();" i need the stupid ;

    why?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    13
    No you don't...something else going on there. Can't tell what without the context.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    MI, US
    Posts
    66
    Rep Power
    28
    Yes, people are right. There is no need for ';' is that's the only function being called. But most often, if the javascript: function needs to return an undefined value to ensure that when people click on the link it doesn't try to go somewhere else but invokes the function instead. That's why people tend to say "javascript:newWin();void(0)" to ensure the browser is not navigated away from the current window.

    If you don't like that, just make sure that your "newWin()" returns void(0) as the very last expression.

    But back to your initial question, you DO NOT NEED ';' if only one function is being called!
  6. #4
  7. No Profile Picture
    =) wannabe?
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2002
    Location
    florida
    Posts
    2,153
    Rep Power
    15
    oh ok.

    the original script was to open a new window.

    function newWin() {

    window.open('mypage.php', 'My Page', 'width=500, height=400')

    }

    then the link
    <a href="javascript:newWin()">My Page</a>


    is that even right?
  8. #5
  9. Traveler
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    UK
    Posts
    45
    Rep Power
    12
    Ah but one is in a function in Javascript and the other calls the Javascript function.

    To me that's like comparing apples and pears.

    I put ";" everywhere anyway

    Last edited by chillpad; April 15th, 2003 at 02:33 AM.


    (**Don't forget your towel**)
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Posts
    1,882
    Rep Power
    19
    window.open('mypage.php', 'My Page', 'width=500, height=400')


    spaces are not allowed in the window name

    Code:
    window.open('mypage.php', 'MyPage', 'width=500, height=400')
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    MI, US
    Posts
    66
    Rep Power
    28
    Originally posted by degsy

    Code:
    window.open('mypage.php', 'MyPage', 'width=500, height=400')
    Spaces are not allowed in the window attributes as well. Make sure that there is no space after comma:
    Code:
    window.open('mypage.php', 'MyPage', 'width=500,height=400')

IMN logo majestic logo threadwatch logo seochat tools logo