Javascript Element How to - Check Document.referrer contains given string or not








Question

We would like to know how to check Document.referrer contains given string or not.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from   www .j  a  v a2 s.  c  om-->
var ref1= "http://yoursite.com/home/index.html";
var search = "home/index.html";
if (ref1.indexOf(search) > -1)
    document.writeln('Found');
else 
    document.writeln('Not Found !');

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: