I would like to parse all of the HTML within a document and if there is a link to a PDF, add an onClick event.
Example:
<a href="/files/report.pdf">Report</a>
Becomes:
<a href="/files/report.pdf" onclick="javascript: _gaq.push(['_trackPageview', '/files/report.pdf']);">Report</a>
The following code works in Chrome/Firefox but not on IE9:
function AddGaqPush()
    {
        var links = document.getElementsByTagName("a");
        for (var i=0; i < links.length; i++)
        {
            if (links[i].href.indexOf(".pdf") !== -1)
            {
                links[i].setAttribute("onclick", "javascript: _gaq.push(['_trackPageview', '" + links[i].href + "']);");
            }
        }
    }
Edited to add: IE settings: Browser Mode: IE9; Document Mode: IE9 Standards
 
     
     
    