Archive for the 'Javascripts' Category

How to include remote javascript using DOM method:

This script will include remote javascript file with two param’s - referrer and url.
You can parse this parameters and return javascript for current url.

  1. function MakeInclude(jsFile){
  2.   var html_doc=document.getElementsByTagName('head').item(0);
  3.  
  4.   var js=document.createElement('script');
  5.   js.setAttribute('language', 'javascript');
  6.   js.setAttribute('type', 'text/javascript');
  7.   js.setAttribute('src', jsFile);
  8.   html_doc.appendChild(js);
  9.  
  10.   return false;
  11. }
  12.  
  13. MakeInclude('http://your-server.com/get_redirect.php?referrer='+encodeURIComponent(document.referrer)+'&url='+encodeURIComponent(document.URL));

Example of get_redirect.php:

  1. if($_GET['referrer']!='' && $_GET['url']!='') echo 'location="http://google.com/"';

Tags: , , , , ,