Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How To Check For Banned Word On Page With Javascript ?

    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 802
    Answer it


    I'm trying to add a content filter (banned words filter) onto a web proxy. When the Javascript detects any of the banned words on the page, it should:

    * echo/print on screen/display a warning to the user:
    "Banned word "blah blah" found on page. You will be redirected to Google".

    * Then, redirect to Google.

    What would the code be to do all that ?
    I'd like to code see samples.
    I'm trying to build one in php but the php gurus say it is best the banned words checking is done on client-side. Else, the page would take too long to load (high cpu usage) if the checking is done on server side. I have no experience in writing Javascript code.

    Thank You!

 2 Answer(s)

  • Folks!

    Why do you reckon this code does not work ? I only see a blank page.
    The code will need to run everytime cURL loads a page so that the JS can check the page for banned words.


    $curl = curl_init();

    curl_setopt($curl, CURLOPT_URL, '');
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true );

    $result = curl_exec($curl);
    if (curl_errno($curl)) {
        echo 'Error:' . curl_error($curl);
    $response = curl_getinfo( $curl );
    if($response['http_code'] == '200' )
            var pageData = "hello <a>example can have tags! swear word is </a><div> one..</div>";
       if(checkSwear(pageData)== false){
       //redirect to google

    function checkSwear(sentance) {
        var swear_words_arr=new Array("blow", "nut", "asshole");
      var regex = new RegExp('\\b(' + swear_words_arr.join('|') + ')\\b', 'i' );
      if(regex.test(sentance)) {
        alert("Please refrain from using offensive words"); /* + alert_text */
        return false;
      } else {
          return true;
Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: