SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Great White North
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what's wrong with this code?

    Hello...

    I'm attempting to open a simple window to call a page and continue to recieve an error with a generic message... "Syntax error"

    here's the code:

    Code:
    <li><a href="javascript:void()" onclick="window.open('act.htm','Area_Conversion','width=300,height=250')">Area Conversion Tool</a></li>
    another pair of eyes would be a great help... I've been looing at this for much to long!

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should be javascript:void(0).

    Another (better IMHO) way of doing the same thing:

    Code:
    <a 
      href="act.htm" 
      target="Area_Conversion"
      onclick="window.open(this.href, this.target,'width=300,height=250'); return false">
         Area Conversion Tool</a>

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Great White North
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog
    Should be javascript:void(0).

    Another (better IMHO) way of doing the same thing:

    Code:
    <a 
      href="act.htm" 
      target="Area_Conversion"
      onclick="window.open(this.href, this.target,'width=300,height=250'); return false">
         Area Conversion Tool</a>
    cool... I've never seen that.

    For the sake of conversation, why is that method better?

    thank you very much! I appreciate the help.

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by cob
    For the sake of conversation, why is that method better?
    Because it will work for those that have disabled Javascript in their browser.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is your link:

    <li><a href="javascript:void()" onclick="window.open('act.htm','Area_Conversion','width=300,height=250')">Area Conversion Tool</a></li>

    Effectively, this is your link when javascript is disabled:

    <li><a href="">Area Conversion Tool</a></li>

    so nothing is going to happen when the user clicks on it because there is no href. If you specify a page in the href, then users without javascript will at least get taken to some page. For people with javascript, you add an onclick event handler to create the effect you want, then return false to cancel the click which prevents the href page from loading.

  6. #6
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by 7stud
    so nothing is going to happen when the user clicks on it because there is no href.
    In Firefox, it will become a link to the current page (so the page will reload when the link is clicked).
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In IE, it reloads something too--at least when I test it locally.

  8. #8
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Great White North
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lilleman
    Hi,

    Because it will work for those that have disabled Javascript in their browser.
    I see. but what happens if you are serving up XHTML strict pages?

    I thought the target attribute was deprecated?

  9. #9
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cob
    For the sake of conversation, why is that method better?
    For any reason you can imagine

    - It works with javascript disabled
    - It works with popups disabled
    - It doesn't confuse users and shows a correct url in status bar (instead a cryptic "javascript" stuff)
    - It works with php sessions and other server-side url rewriters
    - And last not least... It allows google and other robots follow the link.

    Seriously, I think this method is not "better", it's "only possible".

  10. #10
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cob
    I see. but what happens if you are serving up XHTML strict pages?
    I thought the target attribute was deprecated?
    If you need something that isn't strict, dont be strict. Be transitional.

  11. #11
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Great White North
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog
    If you need something that isn't strict, dont be strict. Be transitional.
    words to live by....

  12. #12
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i couldnt find any problem!!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •