The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Opening in a new tab?
zigz321
post 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>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 12 2014, 06:26 AM
Post #2


Don't like donuts. Don't do MySpace.
********

Group: WDG Moderators
Posts: 17,883
Joined: 9-August 06
Member No.: 6



Well, this isn't HTML. It's JavaScript. tongue.gif

Instead of window.location use window.open() .

I think this should work.

CODE
window.open(link[wLink]);
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
zigz321
post 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!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 12 2014, 12:45 PM
Post #4


Don't like donuts. Don't do MySpace.
********

Group: WDG Moderators
Posts: 17,883
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. blush.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 21st April 2018 - 07:41 PM