#1
  1. Rut row Raggy!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    Tornado Alley
    Posts
    560
    Rep Power
    31

    Question Opening new window using JavaScript


    I'm trying to create a link that opens a pop-up windows using JavaScript. It works, except when you click on the link, it takes you back to the index page...no matter where you are. Why? My code is listed below.

    <a href="#" onclick="javascript:window.open('http://localhost/testing/poll/poll.html','none','width=550,height=400');">This month's poll</a>
    Matt
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    24
    Can't replicate the problem here but, try:

    <a href="javascript: window.open('http://localhost/testing/poll/poll.html','none','width=550,height=400');">This month's poll</a>

    instead.
  4. #3
  5. Rut row Raggy!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    Tornado Alley
    Posts
    560
    Rep Power
    31
    Thanks, but that doesn't work either. Now it just displays a white page with the text "[object]" at the top. I would prefer that the current page be displayed, not a blank page or the index page. Any other ideas?
    Matt
  6. #4
  7. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    <a href="javascript:void window.open('http://localhost/testing/poll/poll.html','','width=550,height=400');">This month's poll</a>
  8. #5
  9. Rut row Raggy!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    Tornado Alley
    Posts
    560
    Rep Power
    31
    Thanks I figured it out. I needed to create a function and call that function in the link.
    Matt
  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
    Actually - no. You just needed to void the return value of window.open - so the javascript&#58; url wouldn't try to load a new document. Try it!

IMN logo majestic logo threadwatch logo seochat tools logo