Opening in a new tab? |
Opening in a new tab? |
zigz321 |
Sep 12 2014, 01:50 AM
Post
#1
|
Group: Members Posts: 2 Joined: 12-September 14 Member No.: 21,539 |
I found this random list generator online but needed the button to open the links in a new tab. If someone could modify the code to make it do just that. By the way, i am new to HTML so an explanation would be nice as well.
Heres the code: <HEAD> <script language="JavaScript"> <!-- function get_random() { var ranNum= Math.floor(Math.random()*5); return ranNum; } function gLink() { var wLink=get_random(); var link=new Array(5) link[0]="http://www.google.com"; link[1]="http://www.msn.com"; link[2]="http://www.yahoo.com"; link[3]="http://www.ebay.com"; link[4]="http://www.cnn.com"; window.location = (link[wLink]); } //--> </SCRIPT> </HEAD> <BODY> <FORM name="gotolink"> <INPUT TYPE="button" value="Go to random link!" onClick="gLink()"> </FORM> </BODY> |
pandy |
Sep 12 2014, 06:26 AM
Post
#2
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
Well, this isn't HTML. It's JavaScript.
Instead of window.location use window.open() . I think this should work. CODE window.open(link[wLink]); |
zigz321 |
Sep 12 2014, 11:53 AM
Post
#3
|
Group: Members Posts: 2 Joined: 12-September 14 Member No.: 21,539 |
Whoops, didnt realize it was javascript. Anyways, thanks for your help!
|
pandy |
Sep 12 2014, 12:45 PM
Post
#4
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
Whooops right back at you! I had a fat typo in the code snip above (corrected it now). My fat little fingers wrote window.lopen() instead of window.open(). The former won't work.
|
Lo-Fi Version | Time is now: 19th April 2024 - 08:02 PM |