Does anyone know of a method to capture the url someone has clicked on when they are leaving your site? I'd like to know the destination of a visitor if they click on an ad or type in a new address. It would be helpful to know where they are going, moreso than just the url of the page they exited from.
You could do it with a JavaScript embedded on all your pages that do something based on when the user leaves. A more common way of doing it would be to make all your links clickable to a script that redirects.
I use the redirect on my own web site. For the corporate site I maintain, we don't have many external links, only to our other division's sites. However, I'd like to know if a person goes back to where they came from, types in a new address or clicks on one of our division's sites (don't want to loose the anchor text links for redirection). So, in javascript, what method would I use on the onExit function, to capture the url and store it in a database?
"types in a new address..." now you are getting into privacy issues.... who do you think you are...google?
you must have a PHP that does the database job... and then from javascript you take the url of the current page stored in window.location.href into a variable then you pase it to the PHP using an image document.getElementById('imageid').src= 'http://path_to_php?exitURL='+window.location.href; that should do it... from here is a PHP job
window.location.href does not gets its value from the address bar. see this page: http://www.moshbox.com/testing/window-location-href.html change the address bar value and press the first link. .
... funny guy you cannot, by any means cannot capture what it's written in the address bar... you can capture that only if you press enter after you type in something new as for the mail topic starter... if you want to track the url they click on right before they live... instead of using window.location.href... use the url in the link they clicked on... this means you have to redirect all the links
I found this thread while looking for a solution to this problem. Here is what I've come up with so far. No need to screw around with your link tags -- just add the image tag in your document to direct log data to the PHP script (or whatever). Works with Explorer 6 and Firefox, untested with other browsers. <html> <head> <script> document.onclick = exitURL; // route all click events function exitURL(e) { if (!document.getElementById) return true; // DOM only var eTag = document.getElementById('tracker'); var uLog = '/path/to/logscript.php?url='; var isLink = false; if (!e) { var e = window.event; // IE var elmClick = e.srcElement; } else { var elmClick = e.target; // FF } while (String(elmClick.nodeName) != "A") { elmClick=elmClick.parentNode; // up the tree if (String(elmClick.nodeName) == "HTML") return true; } url = String(elmClick); if (url.indexOf("http") != -1 && url.indexOf(location.hostname) == -1) { eTag.onerror = function() { document.location.href = url; } eTag.src = uLog + url; return false; // wait for log, then leave page } return true; // pass back to originating object } </script> </head> <body> <a href='http://www.example.com'>Example</a> <img id='tracker' width=0 height=0 border=0> </body> </html> Code (markup): All click events are routed through this function, which checks to make sure it's an anchor tag. The indexOf checks for http (non-local) links on different hostnames. The onerror event fires when the image fails to load (because it's not really an image), which then directs the browser to the requested page. Should fail cleanly on browsers that don't support it.
Hi Change This code, but not work iframe please help while (String(elmClick.nodeName) == "A") {alert(elmClick);