• <script>
    <!–
    /*
    */

    //specify random links below. You can have as many as you want
    var randomlinks=new Array()

    randomlinks[0]=”http://facebook.com&#8221;
    randomlinks[1]=”http://gmail.com&#8221;
    randomlinks[2]=”http://yahoo.com&#8221;
    randomlinks[3]=”http://cnn.com&#8221;
    randomlinks[4]=”http://www.geocities.com&#8221;

    function randomlink(){
    window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
    }
    //–>
    </script>
    <form method=”post”>
    <p><input type=”button” name=”B1″ value=”Button >>” onclick=”randomlink()”></p> </form>

    <!–Uncomment below to use a regular text link instead
    Random Link
    –>

    i have this script which open any random link everytime when user click on a button but i want to to customize script like this.

    like when user click 1st time on a button then 1st website will be open in new page
    and when same user click Second time on a button then 2nd website will be open in new page
    and When same user click Third Time on a button then Main Destination Page Will be open.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @asifshaikhtsn

    This is not a WordPress question, so the answers you get from here might not be the right ones for you. Also, please don’t post duplicate topics on the same issue. (https://wordpress.org/support/topic/multiple-links-in-one-website/)

    Here’s an adapted javascript snippet that might help you. It’s not the best – I just customized your given code.

    <script>
    var links=new Array(); var i=0; 
    
    links[0]="http://facebook.com";
    links[1]="http://gmail.com"
    links[2]="http://yahoo.com";
    links[3]="http://cnn.com";
    links[4]="http://www.geocities.com";
    
    /* add as many links as you want */
    
    function getmenextlink(){
    window.open(links[i%links.length]);
    i++; }
    </script>
    
    <input type="button" value="Button" onclick="getmenextlink()">

    Keep in mind that some browsers prevent javascript from opening multiple windows. This needs further testing.

    Hope this helps,
    Kind regards!

    Thread Starter tech techno

    (@asifshaikhtsn)

    Thank You So Much @vladytimy i’ll Hope your code will be work for me but i m totally new in wordpress that’s why i don’t know much about it so can you please help me..
    i want to know that where i need to add this code …
    thank you one again @vladytimy

    Again, this might not be the best approach, but I’m following with your initial code.

    Install and activate this plugin: https://wordpress.org/plugins/insert-headers-and-footers/ Go to Dashboard > Settings > Insert Headers and Footers > Scripts in Footer and paste this code:

    <script>
    var links=new Array()
    var i=0; 
    links[0]="http://facebook.com";
    links[1]="http://gmail.com"
    links[2]="http://yahoo.com";
    links[3]="http://cnn.com";
    links[4]="http://www.geocities.com";
    function getmenextlink(){
    window.open(links[i%links.length]);
    i++;
    }
    </script>

    Then, in your Post/Page Editor/Widgets, add the Custom HTML block and put in it:

    <input type="button" value="Click me now!" onclick="getmenextlink()">

    You might want to style your button based on your preferences.
    If so, add in Dashboard – Appereance – Customize – Additional CSS in the Customizer your desired css styling. For example:

    input[type=button] {
      background-color: #4CAF50; 
      color: white;
      padding: 15px 32px;
      text-align: center;
      text-decoration: none;
      display: inline-block;
      font-size: 20px;
      font-weight:500;
      border:solid 2px #087d13;
      box-shadow: 4px 4px 10px #888888;
    }

    You can learn how to use the Chrome Developer Tools or Firefox Developer Tools to help you see and test changes to your CSS.

    Maybe someone else here has another better solution from the start.

    Hope this helps,
    Kind regards!

    Thread Starter tech techno

    (@asifshaikhtsn)

    whatever you done for me that’s all is very very mean for me and thank you soo much for helping me very much. May God Bless you. Thankh You Soo Much

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can Some Customize This Script please’ is closed to new replies.