0

I want to make a button that takes you to a random website when clicked and I was wondering if there is any way of accessing web servers or something like that to randomly go to a website instead of making a huge array with dozens of websites like this:

var array = ['Lots','of','websites','here']
button.click(array[random])
  • 1
    Yes. Simply loop through all of the different letters of the alphabet, and allow for attempts for combinations between 4 and 20 characters in length. Then append `.com`, and redirect. However, there's no way of knowing whether you'll end up on a **valid** website or not without building them into an array, or piggybacking off of someone like Google. – Obsidian Age May 17 '17 at 23:57
  • 1
    Why don't you just redirect them to Google's "Feeling lucky?" page? – Barmar May 18 '17 at 00:00
  • You could ping the random URL you generate and if you get a response it's most likely a valid website, you'd need to make it slightly less than random for this to not take an eternity though. – aaronw May 18 '17 at 00:05
  • Just pick from the master list: https://www.whoisxmlapi.com/all-registered-domains.php – Scott Marcus May 18 '17 at 00:06
  • @ObsidianAge That's way too complicated for a very simple premise,but very interesting.I'll think about something I can use this technique in. –  May 18 '17 at 00:09
  • 1
    var website = "http://dilbert.com/strip/2001-10-25"; – le_m May 18 '17 at 00:12
  • @aaronw How do you ping a website from Javascript? – Barmar May 18 '17 at 00:24
  • You can't really 'ping' a website from Javascript you would have to ping it on your server and do an ajax call to your server to get the result of that ping. There is a few ways to kind of trick javascript into letting you know if a website exists although some of these are apparently deprecated. [This](http://stackoverflow.com/questions/4282151/is-it-possible-to-ping-a-server-from-javascript) question has some examples. – aaronw May 18 '17 at 00:36

1 Answers1

0

Just redirect:

window.location.href = 'https://www.discuvver.com/jump2.php';

or some site like that.