![]() |
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 |
Just don't with PHP :)
Quicker and easier. |
Quote:
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'; } |
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