/    Sign up×
Community /Pin to ProfileBookmark

Hi,

Just sorting some accessibility bits and bobs with my site.

I have a few a tags that open in a new window if js is on and in the current if its unavailable…

what I want is to add ‘opens in new window’ to the text of the link..

something like this

[CODE]<a onclick=”window.open(this.href); return false;” onkeypress=”window.open(this.href); return false;” href=”http://www.asite.co.uk”>www.asite.co.uk <script type=”text/javascript”> this.innerHTML += ‘(opens new window)’;</script></a>[/CODE]

If anyone could help with this I would be very grateful…

Thanks in advance

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoMar 01.2007 — Call this onload:
function addToA(){
var as = document.getElementsByTagName('a');
for(var i=0;i&lt;as.length;i++)
as[i].firstChild.data += '(opens in new window)';
return;
}


Of course, that adds it to every <a> object on the page. TO specify specific ones you will have to put them all in a containing object such as a DIV, or give them a class.
Copy linkTweet thisAlerts:
@ToonMarinerauthorMar 01.2007 — Is there no way of referenceing the current element inside <script> tags..

not all links open in a new window - even in the same div some do some don't.
Copy linkTweet thisAlerts:
@konithomimoMar 01.2007 — Then you would have to assign them a class, or if they all open up to the same directory/site, then you can check their href attribute, as long as no other <a> objects open to the same direectory/site. The best solution is to just give them a class though.
×

Success!

Help @ToonMariner 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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