![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Oct 2002
Location: Toronto, ON
Posts: 5,247
|
Javascript to alternate between two sources
Anyone have a code handy that would allow you to alternate between two javascript sources with each page load? Right now I have:
<SCRIPT LANGUAGE="JavaScript" SRC="1.js"> </SCRIPT> And <SCRIPT LANGUAGE="JavaScript" SRC="2.js"> </SCRIPT> I'd like to only load one, and make it 50/50 between 1.js and 2.js
__________________
ICQ: 91139591 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
|
you could save the last one loaded in a cookie and then keep alternating... if you don't need to it to be absolutely perfect an easier method would be to just use a random number, 1 or 2 :P
__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Apr 2009
Posts: 1,319
|
You will not get a solid 50/50 split unless you keep a count for each one. Random is usually pretty close but it could easily go 60/40 or worse, or better... it's called random for a reason.
__________________
History will be kind to me for I intend to write it. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Jan 2009
Posts: 420
|
If you want an even 50/50 split, your best implementation would most likely be accomplished server side, using PHP etc..
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
Bullshit. Go flip a coin 1,000,000 times and tell me if it goes out to 60/40.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Industry Role:
Join Date: Oct 2002
Location: Toronto, ON
Posts: 5,247
|
Would this do it?
<script type="text/javascript"> <!-- var rand = Math.floor(Math.random()*2)+1; document.write('<script type="text/javascript" src="'+rand+'.js");</script>'); </script>
__________________
ICQ: 91139591 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
If PHP is in your reach, try:
<SCRIPT LANGUAGE="JavaScript" SRC="<?=rand(1,2)?>.js"> If not: <script> var oHead = document.getElementsByTagName('HEAD').item(0); var oScript= document.createElement("script"); oScript.type = "text/javascript"; oScript.src= Math.floor ( Math.random ( ) * 2 + 1 )+".js"; oHead.appendChild( oScript); </script> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
Quote:
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Industry Role:
Join Date: Oct 2002
Location: Toronto, ON
Posts: 5,247
|
Thanks Quantum, I'll give it a shot.
![]()
__________________
ICQ: 91139591 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
|
It IS possible... unlikely but still possible... It also has a LOT to do with sample size :P
__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 | |
Confirmed User
Join Date: Apr 2009
Posts: 1,319
|
Quote:
Also, BestXXXPorn is correct. The sample size plays a huge role. If you have 100 hits, it could very easily go 60/40.
__________________
History will be kind to me for I intend to write it. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 | |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
Quote:
Previous flips do not influence this chance. Therefore, it WILL average out very close to 50/50 over a large sample set - that's why I said 'flip a coin 1,000,000 times' ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 | |
Confirmed User
Join Date: Apr 2009
Posts: 1,319
|
Quote:
Not to mention if he wanted to add a 3rd option, the "averages" are much worse.
__________________
History will be kind to me for I intend to write it. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |