The IWDN

Advanced Search





You are not logged in.

IWDN Forum Index > Web Development > Web Design, Structure and Style >> Since Target isn't allowed, what do I do?

Reply
 
Thread Tools
Old March 5th, 2007, 12:51   #1
royroi
Web Professional
 
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
royroi is offline   Reply With Quote
Old March 5th, 2007, 13:00   #2
Jamie's Avatar
Jamie
IWDN Admin
 
Join Date: Oct 2004
Location: West Yorkshire, UK
Posts: 6,505
You should use Javascript. http://www.456bereastreet.com/archiv...n_new_windows/
__________________
JamieHarrop.com - Young Entrepreneur... the life as

Subsribe to my RSS feed
Jamie is offline   Reply With Quote
Old March 5th, 2007, 16:58   #3
royroi
Web Professional
 
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?
royroi is offline   Reply With Quote
Old March 5th, 2007, 21:08   #4
the_pm's Avatar
the_pm
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.
__________________
"It's not that a plateau is a bad place to be. It's just that sometimes, it gets a little too comfortable."

- Paul Hirsch, IWDN Administrator


THE RESULTS ARE IN! Read about the Great Search Engine Experiment.
the_pm is offline   Reply With Quote
Old March 7th, 2007, 02:07   #5
BigBison's Avatar
BigBison
<span> is my friend
 
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
BigBison is offline   Reply With Quote
Old March 27th, 2007, 22:42   #6
BigBison's Avatar
BigBison
<span> is my friend
 
Join Date: Oct 2004
Location: Northwest Colorado
Posts: 6,074
Quote:
Quoting BigBison: View Post
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.
BigBison is offline   Reply With Quote
Old March 28th, 2007, 23:41   #7
Corey Bryant's Avatar
Corey Bryant
IWDN Admin
 
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).
__________________
Corey
My Merchant Account Blog | Expression Web Blog
Corey Bryant is offline   Reply With Quote
Old March 28th, 2007, 23:47   #8
BigBison's Avatar
BigBison
<span> is my friend
 
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?
BigBison is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump