JavaScript parse href and add onclick if linking to a PDF
<p>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.</p>

<p>Example:</p>

<pre><code>&lt;a href="/files/report.pdf"&gt;Report&lt;/a&gt;
</code></pre>

<p>Becomes:</p>

<pre><code>&lt;a href="/files/report.pdf" onclick="javascript: _gaq.push(['_trackPageview', '/files/report.pdf']);"&gt;Report&lt;/a&gt;
</code></pre>

<p>The following code works in Chrome/Firefox but not on IE9:</p>

<pre><code>function AddGaqPush()
    {
        var links = document.getElementsByTagName("a");

        for (var i=0; i &lt; links.length; i++)
        {
            if (links[i].href.indexOf(".pdf") !== -1)
            {
                links[i].setAttribute("onclick", "javascript: _gaq.push(['_trackPageview', '" + links[i].href + "']);");
            }
        }
    }
</code></pre>

<p>Edited to add: IE settings: Browser Mode: IE9; Document Mode: IE9 Standards</p>
