User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 401,523 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,396 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 561 | Replies: 4
Reply
Join Date: Dec 2007
Posts: 3
Reputation: tinwindow is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tinwindow tinwindow is offline Offline
Newbie Poster

Help with code change if possible

  #1  
Dec 23rd, 2007
I like this script
one click at a time....only one page at a time in order is what I would like it to do
Not random......
can anyone help me or is there a script i haven't found that does the same..???
Thanx so much for help.....

CODE:
<script>
<!--
/*
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://mysite/page/file"
randomlinks[1]="http://mysite/page/file"
randomlinks[2]="http://mysite/page/file"
randomlinks[3]="http://mysite/page/file"
randomlinks[4]="http://mysite/page/file"

function randomlink(){
window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
}
//-->
</script>
<form>
<p><input type="button" name="B1" value="Random Link >>" onclick="randomlink()"></p> </form>

<!--Uncomment below to use a regular text link instead
<a href="javascript:randomlink()">Random Link</a>
-->
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Posts: 75
Reputation: hielo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 10
hielo hielo is offline Offline
Junior Poster in Training

Re: Help with code change if possible

  #2  
Dec 23rd, 2007
Try this:
<script>
<!--
var counter=0;
//specify random links below. You can have as many as you want
var randomlinks=new Array()

randomlinks[0]="http://mysite/page/file"
randomlinks[1]="http://mysite/page/file"
randomlinks[2]="http://mysite/page/file"
randomlinks[3]="http://mysite/page/file"
randomlinks[4]="http://mysite/page/file"

function randomlink(){
window.location=randomlinks[counter];
counter = (++counter)%randomlinks.length;
}
//-->
</script>
Reply With Quote  
Join Date: Dec 2007
Posts: 3
Reputation: tinwindow is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tinwindow tinwindow is offline Offline
Newbie Poster

Re: Help with code change if possible

  #3  
Dec 23rd, 2007
thanx for the reply hielo...
I tried it out but it does not go to another link...
clicks only one..well the homepage...only...
any idea ???
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,811
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 339
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Help with code change if possible

  #4  
Dec 23rd, 2007
> window.location=randomlinks[counter];
This is incorrect since location is an object or a property of the window object and you are assigning a string to it. The correct way of doing it is location.href = randomlinks[counter]; (window object is implied)

> counter = (++counter)%randomlinks.length;
Don't see this would serve any purpose once the user has navigated away from the page after changing the href...
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Dec 2007
Posts: 3
Reputation: tinwindow is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tinwindow tinwindow is offline Offline
Newbie Poster

Re: Help with code change if possible

  #5  
Dec 23rd, 2007
I have this script in a header which may make a difference.... the button always shows up unless I go to an outside link...not sure but below it is....



This only executes the link the "var counter" is set to... like "3" or "5" or "0"
Can anyone see anything wrong with this ???
I cann't seem to get it to go to the next number when it is clicked again...
============================================================================
<script>
<!--
var counter=3;
//specify random links below. You can have as many as you want
var randomlinks=new Array()

randomlinks[0]="http://www.mysiteone
randomlinks[2]="http://www.mysitetwo
randomlinks[3]="http://www.mysitethree
randomlinks[4]="http://www.mysitefour
randomlinks[5]="http://www.mysitefive

function randomlink(){
location.href = randomlinks[counter];

}
//-->
</script>
=======================
please help me if you can...
thanx
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC