# Randomize coding question

**URL:** <https://forum.readymag.com/t/randomize-coding-question/1797>\
**Category:** Custom code\
**Created:** [July 26, 2023, 4:32am UTC](https://forum.readymag.com/t/randomize-coding-question/1797 "2023-07-26T04:32:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lalala](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/lalala/32/1222_2.png) [@lalala](https://forum.readymag.com/u/lalala)\
**Post date:** [July 26, 2023, 4:32am UTC](https://forum.readymag.com/t/randomize-coding-question/1797/1 "2023-07-26T04:32:32Z")

</div>

im using a paid plan and i would like to use the randomized effect on my page. I’ve been using [this](https://help.readymag.com/hc/en-us/articles/4409523137819) as a reference but the issue im facing is that i don’t want to have a random button for the whole website. i only want it for 4-5 pages. is there a way to code this somehow? i know the bare basics of coding but im not an expert but i would love to make this work!

---

<div class="post-metadata">

**Author:** ![neueMeta](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/neuemeta/32/92_2.png) [@neueMeta](https://forum.readymag.com/u/neueMeta)\
**Post date:** [August 21, 2023, 9:28am UTC](https://forum.readymag.com/t/randomize-coding-question/1797/2 "2023-08-21T09:28:14Z")

</div>

Hey,

the easiest way would be something like this:

```auto
setTimeout(function() {
    
let links = []; 
links[0] = "http://www.google.com/";
links[1] = "http://www.bing.com/";
links[2] = "http://www.yahoo.com/";
links[3] = "http://www.apple.com/";
  
function openLink() {
  var i = ~~(Math.random() * links.length);
  window.location.href = links[i]; 
  return false;
}
  
  $('[data-id=insert-your-data-id]').on('click', function() {
  
openLink(); 

  });
  
    }, 1000); 

```

make sure to paste the data-id of your randomizebutton.

---

<div class="post-metadata">

**Author:** ![lalala](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/lalala/32/1222_2.png) [@lalala](https://forum.readymag.com/u/lalala)\
**Post date:** [August 24, 2023, 9:13pm UTC](https://forum.readymag.com/t/randomize-coding-question/1797/3 "2023-08-24T21:13:11Z")

</div>

hey, thanks so much! \<3 so if the links that i wanted to randomize is within my website (within the readymag pages) then how would i add the links for that?

---

<div class="post-metadata">

**Author:** ![neueMeta](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/neuemeta/32/92_2.png) [@neueMeta](https://forum.readymag.com/u/neueMeta)\
**Post date:** [August 25, 2023, 9:15am UTC](https://forum.readymag.com/t/randomize-coding-question/1797/4 "2023-08-25T09:15:23Z")

</div>

just paste in the urls of your rm project

---

<div class="post-metadata">

**Author:** ![Aura](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/aura/32/2391_2.png) [@Aura](https://forum.readymag.com/u/Aura)\
**Post date:** [September 10, 2024, 4:41pm UTC](https://forum.readymag.com/t/randomize-coding-question/1797/5 "2024-09-10T16:41:43Z")

</div>

Hi, I’m using your code as well and have not been able to get it to work, I have put in my pages, inserted the ID of the button widget I used, but when I try to click the button it does nothing. Am I missing something completely obvious?

---

<div class="post-metadata">

**Author:** ![neueMeta](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/neuemeta/32/92_2.png) [@neueMeta](https://forum.readymag.com/u/neueMeta)\
**Post date:** [September 11, 2024, 8:21am UTC](https://forum.readymag.com/t/randomize-coding-question/1797/6 "2024-09-11T08:21:35Z")

</div>

did you put the code in script brackets?

\< script \>  
… code…  
\< /script \>

(erase the blank characters)

---

<div class="post-metadata">

**Author:** ![Aura](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/aura/32/2391_2.png) [@Aura](https://forum.readymag.com/u/Aura)\
**Post date:** [September 11, 2024, 10:06am UTC](https://forum.readymag.com/t/randomize-coding-question/1797/7 "2024-09-11T10:06:04Z")

</div>

That works, thank you! \<3 When I now press the button once and navigate back to the main site and try to press the button again, it doesn’t work. How do I edit the timeout for it to work over and over again without having to reload the entire site?

---

<div class="post-metadata">

**Author:** ![neueMeta](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.readymag.com/neuemeta/32/92_2.png) [@neueMeta](https://forum.readymag.com/u/neueMeta)\
**Post date:** [September 16, 2024, 10:48am UTC](https://forum.readymag.com/t/randomize-coding-question/1797/8 "2024-09-16T10:48:15Z")

</div>

well here the button works again if I go back and click again.

have you tried different browsers?
