SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Open links in new window

    I want to open links marked with class="external" in a new window, how do I do that?

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by drtanz View Post
    I want to open links marked with class="external" in a new window, how do I do that?
    Presumably you want to set the 'target' attribute in a doctype that doesn't allow it. Try this anywhere below the last link:
    Code:
    <script type='text/javascript'>
    
    for( var i = 0, dl = document.links; dl[ i ]; i++ )
     if( /\bexternal\b/.test( dl[ i ].className ) )
      dl[ i ].target = '_blank';
    
    </script>
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Guru
    Join Date
    Nov 2008
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks


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
  •