Advanced Search

Results 1 to 3 of 3

Thread: show links (replacing domain /w current) in status

  1. #1
    Join Date
    Jan 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default show links (replacing domain /w current) in status

    ..:Link Faking:..

    Objective:
    I want to display url of all links in window status onmouseover.
    BUT, I want to extract the domain from all links and replace with my domain for display in status. This is so all links appear to be hosted on the current domain.

    I have written this script and I'm not sure why its not working yet. Please help.

    Code:
    <html><head></head><body>
    //Script goes at end of body
    <script>
    // Get the domain name in the URL of the current page.
    var thispagedomain = ExtractDomainName(document.URL);
    
    // Iterate over any links on the current page.
    for(var i = 0; i <= document.links.length - 1; i++) {
    
       // Store lowercased href info in variable url.
       var url = document.links[i].href.toLowerCase();
       // Go to the top of the loop and continue if variable 
       //   url doesn't start with "http://" (thus, must 
       //   be a URL to the same domain).
       if(url.indexOf('http://') != 0) { continue; }
       // Extract the domain name from variable url.
       var hrefdomain = ExtractDomainName(url);
       var extra = AfterDomain(url);
       // If the extracted domain name is different than the 
       //   domain name of the current web page, give the  
       //   link an onmouseover attribute displaying in status
      //  the current link but replacing the domain with our
      // domain!
       if(thispagedomain != hrefdomain) { 
          document.links[i].onMouseover="window.status='http://'+thispagedomain+extra; return true" 
    document.links[i].onmouseout ="window.status=''; return true"
          }
       }
    
    
    function ExtractDomainName(s) {
    // For the comments, let's assume that s equals
    //   "http://www.books.Example.co.uk:80/page.html"
    
    // Remove http://, if present.
    // (Result is "www.books.Example.co.uk:80/page.html")
    var i = s.indexOf('//');
    if(i > -1) { s = s.substr(i+2); }
    
    // Remove path/file information, if present.
    // (Result is "www.books.Example.co.uk:80")
    i = s.indexOf('/');
    if(i > -1) { s = s.substr(0,i); }
    
    // Remove port number, if present.
    // (Result is "www.books.Example.co.uk")
    i = s.indexOf(':');
    if(i > -1) { s = s.substr(0,i); }
    
    // Return s if no letters (could be an IP address).
    // (Doesn't apply to the example)
    var re = /[a-z]/i;
    if(! re.test(s)) { return s; }
    
    // Split s into chunks on periods, store in array a.
    // (Result is 
    //          "www"
    //          "books"
    //          "Example"
    //          "co"
    //          "uk"
    //    (5 chunks) )
    var a = s.split('.');
    // If less than 2 chunks, it's not really a domain name.
    //   Just return s and be done with it.
    // (Doesn't apply to the example)
    if(a.length < 2) { return s; }
    
    // Create domain name with last 2 chunks of array a.
    // (Result is "co.uk")
    var domain = a[a.length-2] + '.' + a[a.length-1];
    
    // If more than 2 chunks ...
    // (Yes, the example has 5 chunks)
    if(a.length > 2) {
       // ... and if the last two chunks are each exactly 
       //   2 characters long, it's probably a domain with 
       //   the format Example.co.uk. Therefore, insert the 
       //   third from last chunk of array a into the front 
       //   of the domain name.
       // (The example "co.uk" matches those criteria where, if  
       //   "example.com" had been the domain, it would not.)
       // (Result is "Example.co.uk")
       if(a[a.length-2].length==2 && a[a.length-1].length==2) {
          domain = a[a.length-3] + '.' + domain;
          }
       }
    // Lowercase the domain name and return it.
    // (Result is "example.co.uk")
    return domain.toLowerCase();
    } // end of function ExtractDomainName()
    
    // Get path/file information if present.
    // i.e. everything AFTER domain
    // (Result is "/page.html")
    function AfterDomain(s) {
    var i = s.indexOf('//');
    if(i > -1) { s = s.substr(i+2); }
    i = s.indexOf('/');
    if(i > -1) { s = s.substr(i+1); }
    }
    </script></body></html>
    Last edited by trippin; 02-19-2007 at 02:10 PM.

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    The window.status attribute only works in IE, that's one thing. The other is that you haven't initially called any functions. Nothing is activated, basically.
    - Mike

  3. #3
    Join Date
    Jan 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The script is in the body after all other contents therefore it will get loaded last.
    I realize that this is only for IE.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •