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
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 -> https://www.cpaelites.com/Thread-3-to-5-...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 -> https://www.cpaelites.com/Thread-3-to-5-...US-revenue


[Image: giphy.gif]

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


Possibly Related Threads...
Thread Author Replies Views Last Post
  How to make video proof? kazurengan 15 380 Yesterday, 12:09 AM
Last Post: cohzynes
  WP landing page upload problem justinmartin 3 85 2017-12-13, 01:59 AM
Last Post: justinmartin
  Review my Landing Page / Website YoungArt 8 404 2017-12-05, 04:40 AM
Last Post: EnChanter
  Where should I put <script> tags in HTML? Pirata 5 177 2017-12-03, 11:38 AM
Last Post: Pirata
  How can I make a Mediafire content locker ? TheSillyHat 4 183 2017-12-02, 12:56 AM
Last Post: lizha11





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

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