<a> tag to open in new window?

Discussion in 'CSS' started by akinak, Oct 9, 2008.

  1. #1
    I know that I can use <a href="URL" target="_blank"> to open a link in new window. But is there any way that I can do it in CSS?
    example:
    Link is <a href="URL"> </a>..can I add something in CSS so all links open in new window instead of changing every <a> tag.
     
    akinak, Oct 9, 2008 IP
  2. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #2
    CSS is just a style sheet... you could do it, but it'd be a waste of time... how come you don't want to use the "_blank" for the target?
     
    Grit., Oct 9, 2008 IP
  3. mdvaldosta

    mdvaldosta Peon

    Messages:
    4,079
    Likes Received:
    362
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No, it's a html attribute. Try using something like notepad++ so that you can do a find and replace to add that to all hrefs.
     
    mdvaldosta, Oct 9, 2008 IP
  4. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #4
    There is always a JavaScript solution.
     
    djzmo, Oct 9, 2008 IP
  5. steelfrog

    steelfrog Peon

    Messages:
    537
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There is no way to do it in CSS and the (X)HTML way is not valid code. You could do it via JavaScript, but I'd still try and stay away from it as much as possible.
     
    steelfrog, Oct 9, 2008 IP
  6. webdesigners

    webdesigners Banned

    Messages:
    534
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #6
    you can use:- <a href="link" target="blank">anchor text</a> there should not be a _ this may damage the link to open in a new window.
     
    webdesigners, Oct 10, 2008 IP
  7. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I want to do it for the link codes I get from advertisers. I am not sure if I can change their code...thats why.
     
    akinak, Oct 10, 2008 IP
  8. rajku

    rajku Member

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    33
    #8
    Completely agree with "djzmo", there is always a JS solution; weather its a small or big fix, but it works.

    You will have to get that custom JS made to work according to your wish.
     
    rajku, Oct 12, 2008 IP
  9. dmi

    dmi Well-Known Member

    Messages:
    2,705
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    140
    #9
    You can't do it in CSS. It's really okay to do it through '"target="_blank"'... But if you don't want it that way, you can do it through JS.
     
    dmi, Oct 12, 2008 IP
  10. BlueIce08

    BlueIce08 Member

    Messages:
    535
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #10
    I wouldn't worry about changing it purely on the fact that the advertisers may not like it as I am sure most will expect you to use it in the first place.
     
    BlueIce08, Oct 13, 2008 IP
  11. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Thanks all for your help. I think I'll better not change the code..advertisers may not like it.
     
    akinak, Oct 13, 2008 IP
  12. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #12
    Nah, its not that. Just throw this in your <head>, and it changes for all links, unless otherwise specified. Though opening links in new Windows is very annoying.

    <base target="_blank" />
    Code (markup):
    Won't validate strictly though.
     
    blueparukia, Oct 15, 2008 IP
  13. rochow

    rochow Notable Member

    Messages:
    3,991
    Likes Received:
    245
    Best Answers:
    0
    Trophy Points:
    240
    #13
    Really, how? As you said - it's just a stylesheet.
     
    rochow, Oct 15, 2008 IP
  14. buzzmaker

    buzzmaker Peon

    Messages:
    103
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I think target="_blank" is the easiest way to do it. Why make it complex with JS?

    You don't want your readers to leave your web page so, you want to open the advertiser's links in a new window/tab. But I think, if your readers want to stay on your web page (if they find what they are looking for) and don't want to leave your site, they will find a way to open the link in new window. If not, they will anyways come back to your web page.
     
    buzzmaker, Oct 15, 2008 IP
  15. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #15
    Brilliantly says. Every modern browser comes with a "Open in New Window" or "Open in New Tab" nowadays. IE's popup blocker goes insane with new windows, as well.
     
    blueparukia, Oct 15, 2008 IP