How to call external javascript from URL inside function -


i'm try make previous question little more clearer.

so have cpa offer 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, want randomly call , choose between 2 when user click download button.

example scenario:

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

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

in ramdom manners.

i hope make question clear , guys can me. thank much.

you need round using math.round. math.random give number between 0 , 1. rounding ensure 0 or 1. after can use strait in if statement, because 0 false, , 1 - , not 0 - true, in case of numbers. negating true/false instead: !(math.round(math.random())), of course in reverse order, because it's random, not matter. if bothers add ! negate again like: !!(math.round(math.random())).

but if need more 2 outcomes, multiply math.random number of outcomes minus one. example 3 way use: math.round(math.random() * 2). you'll have use if statement in example.

in case need 1 or 2 outcomes, add 1 random number like: math.round(math.random() + 1). return 1 or 2.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script>     function chose() {          // rounding like: math.round(math.random()).         // return 0 or 1.          // negating true/false instead:         // !(math.round(math.random()))         // !0 > true         // !1 > false          // 3 way (or more) random switch use:         // math.round(math.random() * [ways - 1]).         // return 0, 1 or 2.          // case want 1 or 2 results:         // math.round(math.random() + 1).         // return 1 or 2.          return math.round(math.random() + 1);     }      function getresult() {         if ( chose() === 1 ) {             offerone();         } else {              offertwo();         }     }      function loadscript ( id ) {         $('<scr'+'ipt type="text/javascript" src="https://megadownloder.com/script_include.php?id=' + id +'"></scr'+'ipt>').appendto(document.head);     }      function offerone() {         loadscript(1000000);     }      function offertwo() {         loadscript(2000000);     } </script> 

if code uses document.write() , not want overwrite whole page if called after domready, safe put whole script above <head>, , use loadscript function instead, ensure synchronicity!

<script>      function loadscript ( id ) {         document.write('<scr'+'ipt type="text/javascript" src="https://megadownloder.com/script_include.php?id=' + id +'"></scr'+'ipt>');     } </script> 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -