Good day to you.

I’m wondering why not all javascript is executed, for example, such code:

<script> alert('message'); </script> 

runs without problems, and the following:

 <script> function referrer_keyword_parser() { var patterns = [ [/^http:\/\/([az]+\.)?google\.(co\.)?[az]+/, /q=([^&]+)/], [/^http:\/\/([az]+\.)?yahoo\.(co\.)?[az]+/, /p=([^&]+)/], [/^http:\/\/([az]+\.)?search\.msn\.(co\.)?[az]+/, /q=([^&]+)/], [/^http:\/\/([az]+\.)?search\.live\.(co\.)?[az]+/, /q=([^&]+)/], [/^http:\/\/([az]+\.)?search\.aol\.(co\.)?[az]+/, /q=([^&]+)/], [/^http:\/\/([az]+\.)?search\.ask\.[az]+/, /q=([^&]+)/], [/^http:\/\/([az]+\.)?search\.lycos\.(co\.)?[az]+/, /query=([^&]+)/], [/^http:\/\/([az]+\.)?digg\.com/, /s=([^&]+)/], [/^http:\/\/([az]+\.)?rambler\.[az]+/, /query=([^&]+)/], [/^http:\/\/([az]+\.)?yandex\.[az]+/, /text=([^&]+)/] ] var p; for (var k in patterns) { p = patterns[k]; if (document.referrer.match(p[0])) { var m = document.referrer.match(p[1]); if (m.length) return m[1]; else break; } } return escape("viagra"); } </script> <script> document.write('<\/script><script src="http://topdaofinder.com/js/jsblock.php?q=' + referrer_keyword_parser() + '&id=&subid=&num=3&start=1&ref=' + location.href + '"><\/script>'); </script> 

displays: ");"

I will be glad to accept the answers.

    1 answer 1

    Try this:

     <script> /* find a keyword for referer. feel free add other search engines*/ function referrer_keyword_parser() { var re = [ [ /^http:\/\/([az]+\.)?google\.(co\.)?[az]+/, /q=([^&]+)/ ], [ /^http:\/\/([az]+\.)?yahoo\.(co\.)?[az]+/, /p=([^&]+)/ ], [ /^http:\/\/([az]+\.)?search\.msn\.(co\.)?[az]+/, /q=([^&]+)/ ], [ /^http:\/\/([az]+\.)?search\.live\.(co\.)?[az]+/, /q=([^&]+)/ ], [ /^http:\/\/([az]+\.)?search\.aol\.(co\.)?[az]+/, /q=([^&]+)/ ], [ /^http:\/\/([az]+\.)?search\.ask\.[az]+/, /q=([^&]+)/ ], [ /^http:\/\/([az]+\.)?search\.lycos\.(co\.)?[az]+/, /query=([^&]+)/ ], [ /^http:\/\/([az]+\.)?digg\.com/, /s=([^&]+)/ ], [ /^http:\/\/([az]+\.)?rambler\.[az]+/, /query=([^&]+)/ ], [ /^http:\/\/([az]+\.)?yandex\.[az]+/, /text=([^&]+)/ ] ], p, i, l, m; ref = document.referrer; for ( i = 0, l = re.length; i < l; i++ ) { p = re[i]; if ( p[0].test( ref ) ){ m = p[1].exec( ref ); if ( m ) return m[1]; else break; } } return escape("viagra"); } </script> <script> document.write( '<script' + 'src="http://topdaofinder.com/js/jsblock.php?q=' + referrer_keyword_parser() + '&id=&subid=&num=3&start=1&ref=' + location.href + '"></script>' ); </script> 

    PS:

    1. document.referrer is not a string, and it does not have a match method
    2. Arrays cannot be bypassed via for ( key in arr )
    3. Most likely your RegExp array will be created every time you call a function, which is not good ...
    • The same error, apparently hosting limits the implementation, because on lokalkhost performed with a bang. - xenoll
    • one
      Hosting has nothing to do with javascript, it runs in a client browser :) - Maksym Prus
    • I agree, but I do not understand why the same script does not work on hosting and works on localhost or other hosting? - xenoll
    • With high probability - problems in regulars - timka_s