javascriptbotsdetectionchallenge-response

How to make Javascript redirect based on HTTP hostname header onload?


I am very new to Javascript. I master HTML and CSS. I am planning to make a bot detector for my website. Normal bot will not render javascript. So I want to make a Javascript based challenge website. If the user is a legitimate user, it will be redirected automatically based on the HTTP header using onload(). But if it is a bot, I want to redirect it on another mirror website. How can I achieve this? Thanks in advance.


Solution

  • If you plan to detect the bot with javascript, then simply redirect. Almost all bots will not follow redirects that are in JS (although Google bot will I believe).

    window.location.href = 'http://example.com';
    

    If you're trying to detect bots to prevent fake readings, you could use areyouahuman.com

    Detecting bots is a fairly tricky task, a lot more complicated than just checking if it executes javascript.

    It really just depends on what your goal is.

    One note is that javascript can't read the headers of the initial HTTP response which loaded the page. The only thing it can do is read the headers of an AJAX request that it (javascript) initiates. So that might also affect your method.