/    Sign up×
Community /Pin to ProfileBookmark

can you have one simple link system?

I have herd you can do this with css:

anything within my site – open is same window
antthing outside my site – open in new window

can you do this?

to post a comment
CSS

14 Comments(s)

Copy linkTweet thisAlerts:
@BytesMay 01.2006 — Try this maybe:

anything within my site - open is same window:[/QUOTE][CODE]<a href="#" target="_top">Same Browser Window</a>[/CODE]and


anything outside my site - open in new window:[/QUOTE][CODE]<a href="" target="_blank">New (extra) Browser Window</a>[/CODE]
Copy linkTweet thisAlerts:
@felgallMay 01.2006 — Well since the target attribute is deprecated in HTML (but not yet in Javascript) and since you don't want to have to change the HTML anyway and since CSS can only change the appearance of the links and not what they do you could use the following Javascript:

function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=anchors.length-1; i&gt;=0; i--) {
var anchor = anchors[i];
if (anchor.href) &amp;&amp; anchor.href.substr(0,7) == "http://")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
Copy linkTweet thisAlerts:
@CharlesMay 01.2006 — Well since the target attribute is deprecated in HTML (but not yet in Javascript) [/QUOTE]Oy!

1) The "target" attribute is an odd duck. It was removed from HTML but not depricated. ( http://www.w3.org/TR/REC-html40/index/attributes.html )

2) "HTML documents are constrained to conform to the HTML DTD both before and after processing any SCRIPT elements." ( http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.4 )

3) Some, if not all, browsers resolve relative URLs as the tree is being built.
Copy linkTweet thisAlerts:
@slaughtersMay 01.2006 — I'll add that in practical terms "depreciating" an HTML tag is meaningless.

There are tags I know of that have been depreciated since IE3 and IE4 days (6 to 8 years?), yet even Firefox continues to support them.
Copy linkTweet thisAlerts:
@felgallMay 02.2006 — Well regardless of whether target is supposed to be deprecated or not the Javascript that I posted earlier should make all absolute referenced links (ie. external sites) open a new window (provided Javascript is enabled) without having to specifically change the HTML.

depreciating and deprecating are not the same thing. The value of IE3 and 4 has definitely depreciated to way below zero by now and current browsers still support deprecated tags because there are still validly coded web pages that use them.

Deprecating a tag is the way that the people who write the web standards advise that you should stop using that in your development because there is a better way to do it. It doesn't mean that they expect browsers to stop supporting it any time soon. I guess target isn't deprecated because the expectation is that future web development will allow your visitor to choose whether to open a link in a new window or not.
Copy linkTweet thisAlerts:
@nitrexoxideauthorMay 02.2006 — thanks felgall! I will definatly implement that in my site ?
Copy linkTweet thisAlerts:
@nitrexoxideauthorMay 02.2006 — AGGG! It doesnt seem to be working!

See it online at http://nitrexoxide.awardspace.com

Please help
Copy linkTweet thisAlerts:
@felgallMay 02.2006 — Sorry, one stupid typo. Try this.

function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=anchors.length-1; i&gt;=0; i--) {
var anchor = anchors[i];
if (anchor.href &amp;&amp; anchor.href.substr(0,7) == "http://")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
Copy linkTweet thisAlerts:
@nitrexoxideauthorMay 04.2006 — Wow! Thanks! ?

Sorry, I have next to no understanding of javascript ?
Copy linkTweet thisAlerts:
@slaughtersMay 04.2006 — Well since the target attribute is deprecated in HTML ...[/QUOTE]Are you really sure about that? I got curious and went to the w3 site and under the HTML4 specification and they mention that the name of a FRAME can be used for targeting:

[I][B]name = cdata [CI][/B]

This attribute assigns a name to the current frame. [B]This name may be used as the target of subsequent links.[/B][/I]


http://www.w3.org/TR/html4/present/frames.html#h-16.5

And under

http://www.w3.org/TR/html4/present/frames.html#adef-target

They say:

[I]By assigning a name to a frame via the name attribute, authors can refer to it as the "target" of links defined by other elements. [B]The target attribute may be set for elements that create links[/B] (A, LINK), image maps (AREA), and forms (FORM).[/I]
Copy linkTweet thisAlerts:
@CharlesMay 04.2006 — Regarding the "target" attribute. See my note above and then go to http://www.w3.org/TR/REC-html40/sgml/dtd.html . That'll take you to the formal definition of HTML 4.01. It's in a short hand but do a search for "target". You won't find one.

Then go to the summary of attributes at http://www.w3.org/TR/REC-html40/sgml/dtd.html . You'll note that "target" has been removed but not depricated.
Copy linkTweet thisAlerts:
@slaughtersMay 04.2006 — Regarding the "target" attribute. See my note above and then go to http://www.w3.org/TR/REC-html40/sgml/dtd.html . That'll take you to the formal definition of HTML 4.01. It's in a short hand but do a search for "target". You won't find one....[/QUOTE]Search for "LINK" instead (or scroll about 4 screens down from the top of the document). You'll find a link to the "LINK" element definition : http://www.w3.org/TR/REC-html40/struct/links.html#edef-LINK which includes information on the target attribute
Copy linkTweet thisAlerts:
@CharlesMay 04.2006 — Search for "LINK" instead (or scroll about 4 screens down from the top of the document). You'll find a link to the "LINK" element definition : http://www.w3.org/TR/REC-html40/struct/links.html#edef-LINK which includes information on the target attribute[/QUOTE]Again and as I wrote above, it's not depricated but neither is it still a part of HTML. It fell through the cracks.
×

Success!

Help @nitrexoxide spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...