|
|
You are not logged in.
March 5th, 2007, 12:51
|
#1
|
Join Date: Aug 2006
Location: Israel
Posts: 319
|
Since Target isn't allowed, what do I do?
on XHTML, there is no attribute "target".
what should I write instead of target="_blank" ?
Roy
|
|
|
March 5th, 2007, 13:00
|
#2
|
Join Date: Oct 2004
Location: West Yorkshire, UK
Posts: 6,505
|
|
|
|
March 5th, 2007, 16:58
|
#3
|
Join Date: Aug 2006
Location: Israel
Posts: 319
|
I checked around in the web and did find solutions with JS, so there's no way without it?
|
|
|
March 5th, 2007, 21:08
|
#4
|
Vision - Action = Bovine Excrement
Join Date: Oct 2004
Posts: 10,252
|
Nope. JS is considered the appropriate technology for opening new windows. This is considered a behavior (as opposed to a structural or stylistic element), and one which end users should be able to override. Regardless, the JS window.open function will work for the vast majority of visitors, and it is easy to create a fallback for it:
<a href="http://www.example.com" onclick="window.open('http://www.example.com'); return false;">Click me </a>
With JS available/enabled, this will open a new window. For the few remaining visitors who are unable to use JavaScript (or whose browsers would be ineffective if new windows were opened), the link will simply open in the same window.
|
|
|
March 7th, 2007, 02:07
|
#5
|
Join Date: Oct 2004
Location: Northwest Colorado
Posts: 6,074
|
This simple script will open any link with rel='external' in a new window:
Code:
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
This code needs to be in an external script, IIRC.
__________________
 Unfrozen Caveman Webmaster
One crazy man can block the well, but it takes the whole village to remove the stone. -Iranian proverb
|
|
|
March 27th, 2007, 22:42
|
#6
|
Join Date: Oct 2004
Location: Northwest Colorado
Posts: 6,074
|
Quote:
Quoting BigBison:
This simple script will open any link with rel='external' in a new window:
|
My integration of microformats has led to rel='external acquaintance url' and such, a use of the rel attribute I had not anticipated when I adapted that script.
Also, on second look it appeared to be an ugly hack so I've stopped using rel='external'. The reason is, I use relative URLs so I don't need to "tag" external URLs in my markup. They're self-tagging -- the external links are the ones that start with "http", so:
Code:
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
if (anchors[i].getAttribute("href").search(/^("http")/))
anchors[i].target = "_blank";
}
}
window.onload = externalLinks;
The loop goes through each <a> tag and checks its href attribute to see if it starts with (that's what the carat /^ indicates in a regex) the string "http", in which case target='_blank' is set.
|
|
|
March 28th, 2007, 23:41
|
#7
|
Join Date: Nov 2004
Location: Castle Rock, CO
Posts: 2,187
|
Thanks BigBison for this. I have been using the other code (since I asked over a year ago). This one might come in handy - I just need to remember not to use absolute links on the menus (like I do at times).
|
|
|
March 28th, 2007, 23:47
|
#8
|
Join Date: Oct 2004
Location: Northwest Colorado
Posts: 6,074
|
No problem. There's an improvement "coming soon" which addresses an important accessibility checkpoint by allowing the site visitor to uncheck a box labeled "External sites open in new tab or window." For now, don't forget to include a <noscript> tag somewhere in your code (I put it in my footer):
<noscript>Disabling scripts causes external links to open normally.</noscript>
You can style the <noscript> element using CSS, and view it with Javascript disabled. Who knows, you may induce someone to enable javascript by giving them no cause for alarm?
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|