I’ve found something common with all browsers (Internet Explorer 6, Firefox, Opera on Windows). If the onFocus event handler attached to an anchor link calls a Javascript function that changes the window.location.href, the browser will first call that function and then go to the link in that anchor.
For example,
<code>&lt;script language=&quot;JavaScript&quot;&gt;<br />
function gotoSite(url) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;window.location.href = this.url;<br />
&nbsp;&nbsp;&nbsp;&nbsp;return true;<br />
}<br />
&lt;/script&gt;<br />
&lt;a href=&quot;http://mtsix.com&quot;<br />
onFocus=&quot;return gotoSite('http://google.com');&quot;&gt;Free Water&lt;/a&gt;<br />
</code>
That would make the browser first make an HTTP request to Google, and then to mtsix.com. What this means is that you could deliberately plant a tracking device for every out going link. Although it means the sacrafice of a non-valid XHTML page because of the event handler, it can be very useful.
I have implimented this method in the new banner of this site. If you don’t see the Media Temple logo on the top right corner, please refresh this page. Then click that logo. There is now an outgoing tracker that I’ve set on that link. For every referer to (mt), the counter attached to that Javascript will increase. Take a look at the code if interested.
In conclusion, the advantages to this are
- Being able to notify yourself when an outgoing link is clicked
- Looking and working normally even if Javascript isn’t enabled
- And being search engine friendly. The crawlers will still visit the link (unless rel=”nofollow”), but not necessarily the requested page by Javascript
To every solution there are always disadvantages:
- It’s Javascript — it will only work if the viewer’s browser has Javascript enabled
It will mess up a nicely coded XHTML page with the insertion of the— Not if the function is assigned inside the Javascript.onFocusevent handler
It’s always possible to make a script that redirect outgoing links, such as outgoing.php?link=http://google.com. Personally, I’ve never liked those. I don’t know what the script is actually doing (maybe I’m just paranoid). Some of them may actually be outgoing.php?linkID=4, which always puts me in doubt where I’m redirected to. It’s also bad for the stats of the redirected page. In the example above, Google would be unable to track which exact page the viewer came from, but only the outgoing.php, which isn’t very helpful for either parties.
Hey, you can remain valid XHTML and stuff, by doing something like
<a href="http://mediatemple.net" title="Powered by Media Temple" id="mediatemple">instead of<a href="http://mediatemple.net" title="Powered by Media Temple" onClick="return gotoMT();">, and then doing, like,bitch = getElementById('mediatemple');. Right?bitch.onclick = function () { window.location.href = "http://mtsix.com/mt/mt.php"; return true; }
Oh yeah right! You can assign functions to event handlers outside of the elements too. Thanks Mathias.
That’s exactly what I was going to suggest as well, but it appears I’m a bit late.
That’s a cool idea, and I think more people could use it. However, using the outgoing.php script also reduces the incentive for spammers, if the links are user-submitted.
You could also use regex’s and php’s output buffer to automatically add the url to the id of all links on a page, and then simply get the element by type instead of ID, and capture all outgoing links (you might want to provide the url in your log though).
I don’t understand half of what you said about coding there. XD I’m a coding-idiot with a site coded with haphazardly strewn codes that are really messy, so you can expect that most of that I didn’t catch. I understand what it does and a bit of how it works, but I’m still in the dark. Couldn’t you just use something on Cpanel to get the same info?
The way you did the banner’s cool, though that place is kinda expensive, even though you get a lot of space/bandwidth. Wow. @.@;;
And redirecting outgoing links is evil, it gives you those weird loops where you can’t go where you want to go. >___<;; (I think… *laughs*)
Nyaa, Cpanel doesn’t indicate what your outgoing links are because it’s simply impossible to track without redirect to yourself first.
Media Temple is great. Really professional :)
For the PHP method you were saying. www.dotlall.com/go/www.mtsix.com
:). it work’s as follows:
go.php-
< ?
$url = $_GET['url'];
if(substr(strtolower($url),0,6) == "http:/"){
$array = explode("/", $url);
header('Location: ' . $array[0] . '//' . $array[1]);
}
else{
header('Location: http://‘ . $url);
}
?>
.htaccess-
RewriteEngine On
RewriteRule ^go/(.*) http://yoursite.com/go.php?url=$1
yeah. it’s pretty simple. logging hits to outgoing sites is simple this way as well if you know a tiny bit of PHP and have a method of databasing. welllllll there you have it.
oh and you might notice the http:/. php apparently takes out the other / because it turns into a comment otherwise. i decided to just work with this rather then find a solution. so i exploded the / to create two arrays, and add a // in between. well there you have it again ;).