Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call external javascript from URL inside function

Tags:

javascript

I'm will try to make my previous question a little more clearer.

So I have to CPA offer from my CPA network using tag.

<script type="text/javascript" src="https://megadownloder.com/script_include.php?id=372715"></script>

and

<script type="text/javascript" src="https://megadownloder.com/script_include.php?id=372716"></script>

Now, I want it to randomly call and choose between the two when the user click the download button.

Example scenario:

When a user clicked download button, the <script type="text/javascript" src="https://megadownloder.com/script_include.php?id=372715"></script> will be called.

When a new user clicked download again the <script type="text/javascript" src="https://megadownloder.com/script_include.php?id=372716"></script> will show.

In ramdom manners.

I hope I make my question clear and you guys can help me. Thank you very much.

like image 425
RaffyM Avatar asked Mar 20 '26 12:03

RaffyM


1 Answers

Just give your script tag an id and then read the src attribute. With slice cut of the last character, and add 5 + (0 or 1 random) to the string again. So the result will be 372715 or 372716 as the id.

If there is no JS active, the src is still valid, but only with this id: 372715

As a side note:
This won't work in your case. The time you manipulate the script src attribute, the script was already loaded. So you should do this on server side.

var dlScr = document.getElementById('dl-script');
dlScr.src = dlScr.src.slice(0, -1) + (5+Math.round(Math.random()));
<script id="dl-script" type="text/javascript" src="https://megadownloder.com/script_include.php?id=372715"></script>
like image 122
Wa Kai Avatar answered Mar 22 '26 02:03

Wa Kai