In a .js you can't. You can insert the js code/link into the IF statement in a PHP file:
<?php $words = array('word', 'another', 'third', 'etc');
$regex = '/(' . implode('|', $words) . ')/';
if (preg_match($regex, $_SERVER['HTTP_REFERER']) === 1) {
// restriced word found, do nothing
} else {...