How to make html (php) file loads random js files every time reloading the page?
2017-01-30, 02:00 PM,
#1
I have a php (html) file. It uses the js file. Let see I have 10 different js files, I need it load different js file every time I reload the page.
Thanks.
Reply
Share This Thread :

2017-01-30, 02:00 PM,
#2
Hey immart247,

I'm the CPA Elites helper bot. If you're not looking for support go ahead and ignore this post. If you are looking for support here's some helpful resources for you to get started:

- Check out the CPA Elites monster compilation thread: [MONSTER] CPA MARKETING TOOLBOX [VIDEOS AND TEXT GUIDES]

- CPA Elites - CPA marketing video starters course: CPA Elites - CPA Marketing Starters Course [VIDEOS]

- We have an advanced search feature you can use in case you don't get the answers you needed, you can find that here: https://www.cpaelites.com/newsearch.php

Tip - Scroll down and look at the (Elites Related Threads), you might find an answer there.

Thanks
ElitesHelper
[Image: elitesmainheader2016.png]
Reply
2017-01-30, 05:21 PM,
#3
<script>
var JSFiles = ['1.js','2.js']; // put all the possible JS files to load.
function randomJS() {
// pick a random file from the list in JSFiles
var index = Math.floor(Math.random()*JSFiles.length);

// Append JS file to head section.
var script = document.createElement('script');
script.src = JSFiles[index];
document.getElementsByTagName('head')[0].appendChild(script);
};
</script>
<body onload="randomJS();">
Latest Thanks - View all

immart247(2017-01-31 12:27 AM) 
Reply
2017-01-31, 07:26 AM,
#4
(2017-01-30, 05:21 PM)naathanz Wrote: <script>
var JSFiles = ['1.js','2.js']; // put all the possible JS files to load.
function randomJS() {
// pick a random file from the list in JSFiles
var index = Math.floor(Math.random()*JSFiles.length);

// Append JS file to head section.
var script = document.createElement('script');
script.src = JSFiles[index];
document.getElementsByTagName('head')[0].appendChild(script);
};
</script>
<body onload="randomJS();">
Thanks.
Normally I use this code to call script in html file:
<script src="job.js" type="text/javascript"></script>
I replace your code to this code but it didn't work.
Reply
2017-01-31, 02:53 PM,
#5
Like you said "Do something better mate." :D
Reply
2017-01-31, 04:44 PM,
#6
(2017-01-31, 07:26 AM)immart247 Wrote:
(2017-01-30, 05:21 PM)naathanz Wrote: <script>
var JSFiles = ['1.js','2.js']; // put all the possible JS files to load.
function randomJS() {
// pick a random file from the list in JSFiles
var index = Math.floor(Math.random()*JSFiles.length);

// Append JS file to head section.
var script = document.createElement('script');
script.src = JSFiles[index];
document.getElementsByTagName('head')[0].appendChild(script);
};
</script>
<body onload="randomJS();">
Thanks.
Normally I use this code to call script in html file:
<script src="job.js" type="text/javascript"></script>
I replace your code to this code but it didn't work.

If you still didn't manage to make it work you can send me files over PM and i will take a look at them :)
Reply
2017-01-31, 05:24 PM,
#7
(2017-01-30, 02:00 PM)immart247 Wrote: I need it load different js file every time I reload the page.

Please be aware that the JavaScript solution above uses a random value. A random value could deliver 1, 1, 1, 2, 2, 2, ... etc. or 1, 1, 1, 1, 1, ... etc. It doesn't exactly change the value in a pattern 1, 2, 1, 2, 1, 2, ... etc. like you need it, since it's random.

What you need is a session based change algorithm, i. e. with a semaphore file, to change the value at every call. But this needs a deeper implementation into your CMS, blog, or whatever you use.

.

My latest thread: 3 to 5 Million US$ revenue



[Image: giphy.gif]

Automate your daily work with Bots!
Then you'll have more time to sleep. ;-)
Reply
2017-02-01, 01:39 AM,
#8
can you right the same code for me CharlieHarper please, i am new to programming.
Reply
2017-02-01, 01:47 AM,
#9
(2017-02-01, 01:39 AM)faithalo Wrote: can you right the same code for me CharlieHarper please, i am new to programming.

Sorry, I'm right in the middle of a big project until March. And I won't code for free, because I'm a professional coder.

.

My latest thread: 3 to 5 Million US$ revenue



[Image: giphy.gif]

Automate your daily work with Bots!
Then you'll have more time to sleep. ;-)
Reply


Related Threads
Thread Author Replies Views Last Post
  Best Blackhat Ways to make Fast money vincenzot_t 16 3,578 Yesterday, 04:11 PM
Last Post: vincenzot_t
  Do the language in landing page has to be the same language as GEO location? SupremeWarrior 6 201 2018-08-15, 07:45 PM
Last Post: CharlieHarper
  Make $200 PayPal in 24 Hours (Autopilot) vasikokk 1 260 2018-07-23, 08:09 PM
Last Post: CharlieHarper
  What do you use to create a Landing Page? grahammiranda13 2 230 2018-07-21, 08:53 AM
Last Post: affmarketer101
  create landing page on blogge outgllat 1 170 2018-07-03, 03:34 PM
Last Post: CharlieHarper





About Us | Contact Us | CPA Elites | Advertise | Stats

© 2013-2018 CPA Elites Ltd
Enhanced by MyBB and WallBB
Return to top