SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: opening in new page
-
Dec 11, 2006, 01:28 #1
- Join Date
- Aug 2004
- Location
- Scotland
- Posts
- 687
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
opening in new page
I am trying to get this script to open the random page in a new window/tab. Not having much luck. Suggestions gratefully received.
<!--
/*
Random link button- By JavaScript Kit (http://javascriptkit.com)
Over 300+ free scripts!
This credit MUST stay intact for use
*/
//specify random links below. You can have as many as you want
var randomlinks=new Array()
randomlinks[0]="http://www.buildingapc.co.uk/index.php"
randomlinks[1]="http://www.buildingapc.co.uk/hardware.php"
randomlinks[2]="http://www.buildingapc.co.uk/harddisk.php"
randomlinks[3]="http://www.buildingapc.co.uk/memoryfit.php"
randomlinks[4]="http://www.buildingapc.co.uk/processor.php"
function randomlink(){
window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
}
//-->
</script>
<form>
<p><center><input type="button" name="B1" value="Random Link >" onclick="randomlink()"></center></p> </form>
<!--Uncomment below to use a regular text link instead
<a href="javascript:randomlink()">Random Link</a>
-->
-
Dec 11, 2006, 01:40 #2
- Join Date
- May 2006
- Location
- Amsterdam
- Posts
- 206
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It looks like you're missing a ; at the end of your js lines.
Also, I believe the correct syntax is window.location.href not window.location but you mentioned that you want to open a new window so that could work like this:
Code:window.open(randomlinks[Math.floor(Math.random()*randomlinks.length)]);
-
Dec 11, 2006, 01:57 #3
- Join Date
- Aug 2004
- Location
- Scotland
- Posts
- 687
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks
that worked a treat. Thanks for your very quick response
Bookmarks