force target=blank for all anchor tags on page

T

TS

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
 
N

neilmcguigan

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
 
K

Kevin Spencer

Yup. Put this in the <head> tag:

<base target="_blank">

--
HTH,

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

TS

thank you sir, that sounds like it!


Kevin Spencer said:
Yup. Put this in the <head> tag:

<base target="_blank">

--
HTH,

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

neilmcguigan

to write this programatically:

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

....

void Page_Load()
{
base1.Attributes["target"]="_blank";
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top