force target=blank for all anchor tags on page

Discussion in 'ASP .Net' started by TS, Oct 6, 2005.

  1. TS

    TS Guest

    is there a way to force all links on a page to open in a new browser window
    without declaring them with a target=_blank attribute?

    some kind of global thing? I thought i saw it in a stylesheet once, but
    can't find it now.

    thanks
     
    TS, Oct 6, 2005
    #1
    1. Advertising

  2. TS

    Patirck Ige Guest

    I think the base html tag should be able to do that.
    Patrick

    "TS" <> wrote in message
    news:...
    > is there a way to force all links on a page to open in a new browser

    window
    > without declaring them with a target=_blank attribute?
    >
    > some kind of global thing? I thought i saw it in a stylesheet once, but
    > can't find it now.
    >
    > thanks
    >
    >
     
    Patirck Ige, Oct 7, 2005
    #2
    1. Advertising

  3. TS

    Guest

    you can try something like this on the client side:

    <script type="text/javascript">
    <!--

    window.onload = function()
    {
    var links = document.links;
    var length = links.length;

    for(var i=0; i<length; i++)
    {
    var link = links;
    if(externalLink(link.href))
    {
    link.target = "_blank";
    }
    }
    }

    function externalLink(href)
    {
    return href.substring(0,10) != "javascript";
    }

    //-->
    </script>

    you don't want to open postback links in a new window, and probably not
    links with "#" as the href either

    cheers
     
    , Oct 7, 2005
    #3
  4. Yup. Put this in the <head> tag:

    <base target="_blank">

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Ambiguity has a certain quality to it.

    "Patirck Ige" <> wrote in message
    news:%...
    >I think the base html tag should be able to do that.
    > Patrick
    >
    > "TS" <> wrote in message
    > news:...
    >> is there a way to force all links on a page to open in a new browser

    > window
    >> without declaring them with a target=_blank attribute?
    >>
    >> some kind of global thing? I thought i saw it in a stylesheet once, but
    >> can't find it now.
    >>
    >> thanks
    >>
    >>

    >
    >
     
    Kevin Spencer, Oct 7, 2005
    #4
  5. TS

    TS Guest

    thank you sir, that sounds like it!


    "Kevin Spencer" <> wrote in message
    news:...
    > Yup. Put this in the <head> tag:
    >
    > <base target="_blank">
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > Ambiguity has a certain quality to it.
    >
    > "Patirck Ige" <> wrote in message
    > news:%...
    >>I think the base html tag should be able to do that.
    >> Patrick
    >>
    >> "TS" <> wrote in message
    >> news:...
    >>> is there a way to force all links on a page to open in a new browser

    >> window
    >>> without declaring them with a target=_blank attribute?
    >>>
    >>> some kind of global thing? I thought i saw it in a stylesheet once, but
    >>> can't find it now.
    >>>
    >>> thanks
    >>>
    >>>

    >>
    >>

    >
    >
     
    TS, Oct 7, 2005
    #5
  6. TS

    Guest

    to write this programatically:

    <base runat="server" id="base1" />

    ....

    void Page_Load()
    {
    base1.Attributes["target"]="_blank";
    }
     
    , Oct 7, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cesar Garcia H

    changing link's target to blank page

    Cesar Garcia H, Apr 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    521
    Cesar Garcia H
    Apr 15, 2005
  2. Rob Nicholson
    Replies:
    3
    Views:
    774
    Rob Nicholson
    May 28, 2005
  3. Aaron Freeman
    Replies:
    7
    Views:
    1,764
    Jonathan N. Little
    Mar 17, 2006
  4. John
    Replies:
    1
    Views:
    96
    Lasse Reichstein Nielsen
    Aug 2, 2003
  5. Pim Sohful

    Setting anchor target and Norton(?)

    Pim Sohful, Aug 23, 2006, in forum: Javascript
    Replies:
    2
    Views:
    110
Loading...

Share This Page