Well, the problem is that you're trying to mix two ways of doing something and I don't think you understand what's going on. Rather than just cutting and pasting stuff, try walking through it logically.
This section is never going to work because it's commented out:
Code:
<!--Uncomment below to use a regular text link instead
<a href="javascript:randomlink();" target="_blank">Random Link</a>
-->
Secondly, inside the "randomlink" function there's this line that is changing the url/location of your current window (hence why it's not opening in a new tab):
Code:
window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
Here's a different way of doing it. Not my preferred way, but hopefully it's straightforward enough that you can understand what's going on:
Code:
<script>
function randomlink(elem){
[indent]var randomlinks=new Array()
randomlinks[0]="http://anandtech.com"
randomlinks[1]="http://xbitlabs.com"
elem.href = randomlinks[Math.floor(Math.random()*randomlinks.length)];
return false;[/indent]
}
</script>
<a href="#" onclick="randomlink(this);" target="_blank">Random Link</a>
When you click the anchor tag it runs your randomlink function and sets the href of that anchor to your random link. Since you have the target="_blank" in there, it will open in a new tab. The link will be randomly generated every time you click on it. Does that make sense?