![]() |
![]() |
![]() |
||||
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: Sep 2009
Posts: 2,302
|
Randomize Which JS Is Called?
I just want to thank everyone in advance for the question I'm asking, especially if you're able to help me out here.
Say I have three javascript files OR pieces of javascript I want to run. I don't care if I'm calling three files, or one with conditions. How do I randomize it so user lands on the website, the command is executed randomly. So mypopup.js advertiserpopup.js anotheroneofmypopups.js Is there a way to randomly call one of those? Or perhaps use it in allpopups.js = 3 codes, randomized per visit. The goal is to not run both a CPM and my own popup at the same time. Thank you! ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
♦ Web Developer ♦
Industry Role:
Join Date: May 2005
Location: Full-Stack Developer
Posts: 12,472
|
Just don't with PHP
![]() Quicker and easier. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Industry Role:
Join Date: Sep 2009
Posts: 2,302
|
I modified this script (4 options, you can change to 3) and replace images with other JS
It worked! But what is this php you speak of? :D I'm calling it in a wordpress theme. And the ads are in javascript to make the popup. Any ideas? var picnumber = Math.floor((Math.random() * 4) + 1); if (picnumber == 1){ img.src = '1.jpg'; } else if (picnumber == 2) { img.src = '2.jpg'; } else if (picnumber == 3) { img.src = '3.jpg'; } else { img.src = '4.jpg'; } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
(>^_^)b
Industry Role:
Join Date: Dec 2011
Posts: 7,224
|
I smoked a bit and I'm kind of rusty with this, but would it be something like this in PHP?:
<?php $a=array("mypopup.js","advertiserpopup.js","anothe roneofmypopups.js"); shuffle($a); echo '<script type="text/javascript" src="'("$a[0]")'"></script>'; ?> I know that there's a better way to randomize by picking out a random number then using that for the array number to use rather than using Shuffle, but it's easier and I don't think there will be much difference in load with 3 variables.
__________________
![]() I've referred over $1.7mil in spending this past year, you should join in. ![]() ![]() I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years.. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() ![]() |
|||||||
|
|||||||
Bookmarks |
Thread Tools | |