GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech Randomize Which JS Is Called? (https://gfy.com/showthread.php?t=1315002)

incredibleworkethic 06-27-2019 04:29 PM

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!:pimp

Miguel T 06-27-2019 04:48 PM

Just don't with PHP :)
Quicker and easier.

incredibleworkethic 06-27-2019 04:51 PM

Quote:

Originally Posted by Miguel T (Post 22491981)
Just don't with PHP :)
Quicker and easier.

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';
}

Colmike9 06-27-2019 06:55 PM

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.


All times are GMT -7. The time now is 08:07 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123