473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

force target=blank for all anchor tags on page

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
Nov 19 '05 #1
5 4607
I think the base html tag should be able to do that.
Patrick

"TS" <ma**********@nospam.nospam> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
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

Nov 19 '05 #2
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[i];
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

Nov 19 '05 #3
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" <na********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
I think the base html tag should be able to do that.
Patrick

"TS" <ma**********@nospam.nospam> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
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


Nov 19 '05 #4
TS
thank you sir, that sounds like it!
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:eC**************@TK2MSFTNGP15.phx.gbl...
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" <na********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
I think the base html tag should be able to do that.
Patrick

"TS" <ma**********@nospam.nospam> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
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



Nov 19 '05 #5
to write this programatically:

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

....

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

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christophe Guillon | last post by:
Hello I would like to have a hypertext link which, when I click on it, leads to a web page where a certain word is highlighted. Depending on the link, the same target page would be displayed but...
2
by: Hazzard | last post by:
I am trying to figure out how to add an additional value to a querystring collection so that when I click on a datagrid cell, there will be a key to distinguish it from another column's...
1
by: VB Programmer | last post by:
I have a long html string I get from a rich text editor. How do I append "target='_blank' to all occurrances of "<A href=..." in the long html string easily? Is there an easy way, or do I have...
15
by: dee | last post by:
Hi, I'm curious why MS decided to have Transfer hide the target page's url invisible? Any guesses ? Thanks. Dee.
8
by: CJM | last post by:
What is the best way to force a page break when printing from a browser? A page in my application generates a series of tables which are usually less than will fit on a page of A4. Ideally I want...
1
by: klynn | last post by:
I just built a .NET app where I put in the page an anchor such as: <a id="whatever" href="somesite" target="_blank">My anchor</a> for just one of my clients, when they click this anchor, ALL of...
4
Dököll
by: Dököll | last post by:
Hey Gang! I thought I had a good idea but then I realized JSF doesn't play that... I am trying to mimick what HTML can do in JSF when using target tags to related to inner HTML pages. In...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.