SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2003
    Location
    los angeles
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I onUnload to get target url?

    Say you have a script you are trying to direct through and some links are in flash and such and cant be tracked with the onClick method. I already set up a php script to track linkthroughs. I need to be able to track browser movement, because not all clickouts/change URLs are using href / html codes. I want to be able to track where users go when they leave my site. I want to use this with onUnload and not script every link and I need to find out where they are going and I'm trying to use the onUnload command. How do I do this or is there an alternative way?

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This little idea is the only thing I can think of right now. This example is IE-only. Let me know if you need help making it cross-browser.
    Code:
    <html>
    <head>
    <script type='text/javascript'>
    window.onload = function()
    {
      document.onclick = docOnClick;
    }
    function docOnClick(e)
    {
      if (event.srcElement.tagName == 'A') {
        return confirm('Goodbye! Enjoy your trip to\n\n' + event.srcElement.href);
      }  
    }
    </script>
    </head>
    <body>
    
    <p><a href='http://sitepointforums.com/'>SPF</a></p>
    <p><a href='http://sitepoint.com/'>SP</a></p>
    <p><a href='http://cross-browser.com/'>CB</a></p>
    
    </body>
    </html>

  3. #3
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Evidently this solved your problem.

    You're welcome.


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
  •