Leros
Lifer
- Jul 11, 2004
- 21,867
- 7
- 81
Each html document has a head section. Usually <head> </head>. The script tags with JavaScript go in there. On my phone on tapa I don't see any code..weird.
JavaScript doesn't have to go in the head section.
Each html document has a head section. Usually <head> </head>. The script tags with JavaScript go in there. On my phone on tapa I don't see any code..weird.
JavaScript doesn't have to go in the head section.
thanks. Can't seem to figure how to get it to open in a new tab but its fime.
This seems like it might work:
http://stackoverflow.com/a/11384018
Edit: apparently this does not work. It get blocked by pop-up blockers which actually makes a lot sense. You can open links in new tabs by setting target="_blank". Not sure if this works, but can you let the anchor actually execute and just change the href value via JavaScript?
Yup, Where you have the a href tags for each section, add target=_blank that will open it up in a new tab.
where does it go in <a href= "javascript:randomlink()" >Random Link</a>
<a href="javascript:randomlink();" target="_blank">Random Link</a>
tried it. for some reason it does not work.Code:<a href="javascript:randomlink();" target="_blank">Random Link</a>
<!--Uncomment below to use a regular text link instead
<a href="javascript:randomlink();" target="_blank">Random Link</a>
-->
window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
<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>
<html>
<head>
<script type="text/javascript">
//random links for example purpose
var randomlinks = [
"http://anandtech.com",
"http://xbitlabs.com",
"http://google.com",
"http://yahoo.com"
];
function setRandomLink() {
var anchor = document.getElementById("randomlink");
anchor.href = randomlinks[Math.floor(Math.random()*randomlinks.length)];
return true;
}
</script>
</head>
<body>
<a id="randomlink" href="#" target="_blank" onclick="setRandomLink();">Random Link</a>
</body>
</html>
