www.webdeveloper.com
Results 1 to 11 of 11

Thread: open a link in a new window...

  1. #1
    Join Date
    Dec 2002
    Posts
    3

    Question open a link in a new window...

    i can't find the command at the html goodies site...

    what is the command so that i could open a link in a new window?

    thanks for your help.^^

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    <a href="http://www.w3.org/" onclick="window.open(this.href); return false">W3C</a>

    or

    <a href="http://www.w3.org/" target="_blank">W3C</a>
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Nov 2002
    Posts
    984
    <a target="_blank" href=""
    // Stefan Huszics

  4. #4
    Join Date
    Dec 2002
    Location
    Grantham, PA
    Posts
    10
    Note that in XHTML 1.1 and higher the target="" attribute is no longer legal.

    Still waiting on an answer for the alternative other than JavaScript, but I think for now I'm just going to go with that. Doesn't really matter anyway...

    BTW, what exactly does the return false do? I notice it has the effect of keeping the parent window at its current location but what are the technicalities? What are we returning false to? The parent window?
    Last edited by matthurne; 12-16-2002 at 05:39 PM.

  5. #5
    Join Date
    Nov 2002
    Posts
    4,473
    You are returning false to the "onClick" event. This basically says the event has been handled, and the default handler doesn't have to do anything. If you leave it out or return true, the default action will begin. In the case of a link, the HREF action is activated.

    Many people code

    <a href="#" onclick="...">

    mostly for browsers that require a HREF in a link. If the "return false" is left out of the "onclick", the browser goes to a null anchor. This will make the page jump to the top, or in some cases, reload.

    The best of both worlds is to use a real HREF and "return false" in the "onclick". This allows browsers with javascript disabled to do something useful.

  6. #6
    Join Date
    Dec 2002
    Location
    Grantham, PA
    Posts
    10
    Cool beans. Thanks.

    I took a class on JavaScript this semester, my exam is Thursday actually. Simple class, very very easy, and we didn't learn too many USEFUL things...some but not too many...sigh.

  7. #7
    Join Date
    Nov 2002
    Posts
    2,632
    Web classes, the ones taught in college at least, tend to be very light in content, and even then they skip over real world stuff. You would think a teacher would have students learn to make web pages against 4.01 recommendations at this point, but they don't. Even in a class that taught one chapter of CSS, the final exam included zero CSS code. We were told to find 20 errors in the given web pages code. I found 35 errors based on 4.01 Strict and I didn't even count taking out the code that should have been done with CSS. :-)

  8. #8
    Join Date
    Dec 2002
    Location
    Grantham, PA
    Posts
    10

    Talking

    Lol. That cracks me up.

  9. #9
    Join Date
    Nov 2002
    Posts
    984
    Originally posted by matthurne
    Note that in XHTML 1.1 and higher the target="" attribute is no longer legal.
    You are wrong.

    Firstly XHTML 2.0 will (very likely, it's still in draft state) have target again.

    Also, Neigher HTML 4.01 and XHTML 1.0 STRICT allows for target either.
    // Stefan Huszics

  10. #10
    Join Date
    Nov 2002
    Posts
    984
    Originally posted by spufi
    Web classes, the ones taught in college at least, tend to be very light in content, and even then they skip over real world stuff. You would think a teacher would have students learn to make web pages against 4.01 recommendations at this point, but they don't. Even in a class that taught one chapter of CSS, the final exam included zero CSS code. We were told to find 20 errors in the given web pages code. I found 35 errors based on 4.01 Strict and I didn't even count taking out the code that should have been done with CSS. :-)
    LOL

    I guess most teachers don't have a first clue about what HTML really is.
    // Stefan Huszics

  11. #11
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    Originally posted by matthurne
    Note that in XHTML 1.1 and higher the target="" attribute is no longer legal.

    Still waiting on an answer for the alternative other than JavaScript, but I think for now I'm just going to go with that. Doesn't really matter anyway...

    BTW, what exactly does the return false do? I notice it has the effect of keeping the parent window at its current location but what are the technicalities? What are we returning false to? The parent window?
    I just want to add two things to gil's excellent post. The event handlers in JavaScript are the only things that don't follow the 'capitalize each new word in the name' convention. It's document.links[1].onclick. And, it's important to remember that 12% of users do not use JavaScript and that many of those who do use JavaScript disable pop-ups. We need the link to behave like a normal link for those people. Better that then a link that does nothing at all. For those good people, the onclick handler will be ignored and the browser will simply load the document. That's why it's important to supply the URL for the HREF attribute.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles