Help with Javascript Link Replacement

I’m trying to finish off a webapp version of my website. I’m really close, but the only thing I’m having trouble with is converting the a href’s to javascript links (so that articles open w/in the app and not in Mobile Safari). I thought I’d found a simple script to help me out, but it turns out that script also messes with my comments plugin (Disqus). I’ll post the script below, but is there any way I can have the script convert all links except those in the div “disqus_thread”?
I researched possible alternatives, but the only solution I could find was to use the script and specify all the other divs. Hopefully someone here can help me out 😛
Thanks,
Matt

   <script>
     var a=document.getElementsByTagName("a");
     for(var i=0;i<a.length;i++)
     {
     a[i].onclick=function()
     {
     window.location=this.getAttribute("href");
     return false
     }
     }
   </script>

Related posts

Leave a Reply

1 comment

  1. I dont know why would you do this. Because you are setting href property of anchor to window.location which anyways will be done by anchor’s defualt behavior.

    If you want to select all the anchor except those inside disqus_thread and execute your logic you can try this. Make sure you include jQuery library into your page.

    $(":not(#disqus_thread)").find("a").click(function(){
       window.location.href = this.href;
       return false;
    });