..: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>



Reply With Quote

Bookmarks