I want all the links in a certain area to be target="_blank". How do I do that? body target="_blank" doesn't work because it sets the whole page to _blank.
Javascript, perhaps - get each anchor in a certain area and set this attribute.
But I would argue it's better to just set target="_blank" on all elements, just for the rare users who aren't using Javascript.
Doesn't make sense to come up with a JS solution and then add target="_blank" to all elements anyway to support JS-disabled visitors.
I've switched careers...
I'm NO LONGER a scientist,
but now a web developer...
awesome.
As I said in my first post, and criterion also reiterated - just append target="_blank" to the links. Doing it with Javascript is a waste of time. Appending target="_blank" is fast (I am assuming your blog is probably powered with wordpress in which case you just need to change one line) versus doing it with JS you need to write a script, and you'll won't achieve the desired effect when people without JS visit.
I've switched careers...
I'm NO LONGER a scientist,
but now a web developer...
awesome.
As I said in my first post, and criterion also reiterated - just append target="_blank" to the links. Doing it with Javascript is a waste of time. Appending target="_blank" is fast (I am assuming your blog is probably powered with wordpress in which case you just need to change one line) versus doing it with JS you need to write a script, and you'll won't achieve the desired effect when people without JS visit.
I was suggesting automating it. I would suggest using _blank only for hrefs that are off-domain though. A regex would make quick work of that and you wouldn't have to remember to change the target manually that way.
JavaScript is way easier. And those of us without JavaScript, we don't want to be bothered with new windows either.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
JavaScript is way easier. And those of us without JavaScript, we don't want to be bothered with new windows either.
You could use the same regex on the server or with Javascript. I'd say both would equally easy it just depends on how many users the OP wants to force to a new window.
Except that I wouldn't use a RegExp. Those things aren't well suited to HTML and, more importantly, this is way easy with DOM methods.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
Eventually, my website might be like Twitter, except smaller. I won't be able to change all the links one by one. I'd need to make all the links into _blank automatically.
What part of "use JavaScript" do you not understand? But if you are trying to change all of them and not a subset then just use the BASE element.
Code:
<script type="text/javascript">
onload = function () {for (i = 0; i < document.links.length; i++) document.links[i].target = 'foo'}
</script>
Last edited by Charles; 05-25-2010 at 10:54 AM.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
Bookmarks